组件代码如下,我在网页上触发更新后的add方法,打印出来的this竟然是window?
Vue.component('button-counter', {
data: function() {
return {
count: 0,
value: 1
}
},
mounted() {
let async = Promise.resolve();
async.then(_ => {
this.count++
this.add = function() {
console.log(this)
}
})
},
methods: {
add: function() {
console.log(0)
}
},
template: '<div><button v-on:click="add">You clicked me {{ count }} times.</button></div>'
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…