Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference in 'vue.js' and 'vue.min.js' with inline statement in event. #8384

Closed
olegvakulenko opened this issue Jun 20, 2018 · 2 comments
Closed

Comments

@olegvakulenko
Copy link

Version

2.5.16

Reproduction link

https://jsfiddle.net/e2oa3k75/

Steps to reproduce

  1. Click on "Test"

What is expected?

https://jsfiddle.net/w5q3ytga/

I expect that 'vue.js' and 'vue.min.js' have same behavior, so I expect to see alert window.

What is actually happening?

https://jsfiddle.net/e2oa3k75/

When I use Development version, inline statement produce warning:

[Vue warn]: Property or method "alert" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

@posva
Copy link
Member

posva commented Jun 20, 2018

You should not use globals in templates, that's why we put the warning. You cannot rely on them always being accessible

@posva posva closed this as completed Jun 20, 2018
@Justineo
Copy link
Member

Justineo commented Jun 20, 2018

https://vuejs.org/v2/guide/installation.html#Explanation-of-Different-Builds

In development builds (in this case vue.js) Vue will use the native Proxy to detect data/methods which are not defined on the component instance so the alert call will be intercepted. For production builds (in this case vue.min.js) the validation logic is removed so the alert call finally fallbacks to window.alert.

Because this validation requires a runtime check which relies on Proxy so we can't do it during compilation but if we keep the runtime check, we'll experience browser compatibility issues and it will kind of bloat the code size.

So I think it's better to just remember this caveat and avoid using global functions inside templates. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants