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(){
的上下文,而不是對象的上下文。
解決了問題...謝謝 –