-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] vue变量名如果以_、$开头的属性会发生什么问题?怎么访问到它们的值? #464
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
Comments
以 _ 或 $ 开头**的属性不会被 Vue 实例代理,因为可能和 Vue 内置的属性、API 方法冲突。可以使用例如 **vm.$data._property |
报错 变量未定义 |
会报undefined |
实例创建之后,可以通过 vm.$data 访问原始数据对象。Vue 实例也代理了 data 对象上所有的属性,因此访问 vm.a 等价于访问 vm.$data.a。 以 _ 或 $ 开头的属性 不会 被 Vue 实例代理,因为它们可能和 Vue 内置的属性、API 方法冲突。你可以使用例如 vm.$data._property 的方式访问这些属性。 |
综上所述:以_ $开头的变量会跟Vue内置的属性,API发生冲突,可以使用.$data.property或者._data.property的方式访问这些属性 |
vue3中_开头的变量会被代理,$开头的才不会,我测了一下 |
[vue] vue变量名如果以_、$开头的属性会发生什么问题?怎么访问到它们的值?
The text was updated successfully, but these errors were encountered: