今天在vue中使用定时器,修改data中的数据,页面不改变
代码是这样的
commonClick(index) {
setTimeout(function () {
this.count = this.count - 1;
this.show = !this.show;
}, 200);
},
修改this指向后,页面更新,**注意vue中this的指向问题!!!**萌新一个,哪里有问题希望大家指出来!
commonClick(index) {
let _this = this;
setTimeout(function () {
console.log(this)//window
_this.count = _this.count - 1;
_this.show = !_this.show;
}, 200);
},