-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 在使用计算属性的时,函数名和data数据源中的数据可以同名吗? #558
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
不可以,同名会报错:The computed property "xxxx" is already defined in data |
不能同名 因为不管是计算属性还是data还是props 都会被挂载在vm实例上,因此 这三个都不能同名 |
不可以,写在计算属性中的数据名称,不能在data中定义 |
不可以,因为初始化vm的过程,会先把data绑定到vm,再把computed的值绑定到vm,会把data覆盖了 |
莫名其妙的问题。可以同名,但data会覆盖methods。并且本就不该同名,同名说明你命名不规范。 |
其实是可以同名的, 不是先把data绑定到vm,初始化顺序是这样的,先computed,methods,data,props |
为什么会有这样的问题?有点脑残了吧 |
正确顺序:props、methods、data、computed、watch、 |
不可以,会报错, |
不能同名,不管是方法,计算属性还是data最后都会挂载到vue实例上去,如果同名了就会把其中一条覆盖掉,那你写的计算属性,方法,在data中定义的数据,就没有什么意义了 |
在initComputed执行时,会先看看当前vm实例的原型链上有没有这个key,用的in操作符判断 如果没有,那就创建computed |
|
可以同名的吧,只是会告警而已,又不会报错。 |
[vue] 在使用计算属性的时,函数名和data数据源中的数据可以同名吗?
The text was updated successfully, but these errors were encountered: