我有一个带有名为“volume”的状态属性的组件,它绑定到一个滑块元素。我有一个绑定到卷属性的观察者,这样当卷更新时,应该触发一个函数
data () {return {
volume: 0,
}},
methods: {
testMethod () {
console.log("this is firing")
}
},
watch: {
volume: (v) => {
console.log("volume has been updated", v);
this.testMethod();
}
}
运行此代码时,控制台显示错误“无法读取未定义的“testMethod”的属性
我尝试了其他方法,例如访问 $store (这是我最初的问题),但也未能解决。