【发布时间】:2018-10-25 23:02:07
【问题描述】:
我想更改数组数据,在vue方法中更改。
https://codepen.io/deded007/project/editor/AQyykN
我的问题是如何使用这样的变量来更改数据
created() {
var a=this.thisisarray;
this.thisisarray=[10];
console.log('a expected '+this.thisisarray+',but '+ a);
}
直接使用this.thisisarray 没问题。但是更改变量a 不起作用。我的变量仍在查看旧参考。我总是得到a expected 10,but 9999
我想创建一个全局方法并传递我的变量a 来更改它。
Vue.component('page-head', {
template: '#page-head',
data() {
return {
thisisarray:['a','b']
};
},
created() {
var a=this.thisisarray;
this.thisisarray=[10];
console.log('a expected '+this.thisisarray+',but '+ a);
}
})
【问题讨论】:
标签: vue.js vue-component