watch和computed使用箭头函数时,不能用this
在watch和computed中,使用箭头函数的时候,在方法里不要使用this,因为this指向不是vue实例
错误:
vue
computed: {
tdata: () => {
this.ttest()
return ''
}
}
正确:
vue
computed: {
tdata() {
this.ttest()
return ''
}
}
或
computed: {
tdata: function () {
this.ttest()
return ''
}
}