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

[vue] vue变量名如果以_、$开头的属性会发生什么问题?怎么访问到它们的值? #464

Open
haizhilin2013 opened this issue Jun 22, 2019 · 6 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] vue变量名如果以_、$开头的属性会发生什么问题?怎么访问到它们的值?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 22, 2019
@dengBox
Copy link

dengBox commented Jun 28, 2019

以 _ 或 $ 开头**的属性不会被 Vue 实例代理,因为可能和 Vue 内置的属性、API 方法冲突。可以使用例如 **vm.$data._property

@naokimidori
Copy link

报错 变量未定义
以 _ 或 $ 开头的属性 不会 被 Vue 实例代理,因为它们可能和 Vue 内置的属性、API 方法冲突。
你可以使用例如 $data.xxx或者_data.xxx 的方式访问这些属性。

@webread
Copy link

webread commented Jul 17, 2019

会报undefined

@HeMin0919
Copy link

实例创建之后,可以通过 vm.$data 访问原始数据对象。Vue 实例也代理了 data 对象上所有的属性,因此访问 vm.a 等价于访问 vm.$data.a。

以 _ 或 $ 开头的属性 不会 被 Vue 实例代理,因为它们可能和 Vue 内置的属性、API 方法冲突。你可以使用例如 vm.$data._property 的方式访问这些属性。
https://cn.vuejs.org/v2/api/#data)

@yuanyurui
Copy link

综上所述:以_ $开头的变量会跟Vue内置的属性,API发生冲突,可以使用.$data.property或者._data.property的方式访问这些属性

@CODER-ZHM1997
Copy link

vue3中_开头的变量会被代理,$开头的才不会,我测了一下

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

No branches or pull requests

7 participants