0
如何访问vue.js
内部的数据值?访问vue内部的数据值js
代码:
data: function(){
return {
foo: 123,
bar: this.foo
}
}
在这种情况下,我得到了undefined
如何访问vue.js
内部的数据值?访问vue内部的数据值js
代码:
data: function(){
return {
foo: 123,
bar: this.foo
}
}
在这种情况下,我得到了undefined
有几种选择我看到:
data: function(){
const data = {
foo: 123
};
data.bar = data.foo;
return data;
}
或
data: function(){
const data = {
foo: 123
};
return {
...data,
bar: data.foo
};
}
你得undefined
因为this.foo
指的是function(){
的上下文,而不是对象的上下文。
解决了问题...谢谢 –