关于Vue使用watch监听属性报“TypeError: Cannot read properties of undefined (reading ‘apply‘)“的问题
报错信息:Error in callback for immediate watcher “abc”: "TypeError: Cannot read properties of undefined (reading ‘apply’)"解决手段:1、watch当中的方法名写错错误:abc: {immediate: true,headler() { // 这里写错啦!console.log(111)
·
报错信息:
Error in callback for immediate watcher “abc”: "TypeError: Cannot read properties of undefined (reading ‘apply’)"
解决手段:
1、watch当中的方法名写错
错误:
abc: {
immediate: true,
headler() { // 这里写错啦!
console.log(111);
},
},
修改结果为:
abc: {
immediate: true,
handler() {
console.log(111);
},
},
成功:
2、当使用this指向data时报错(使用普通函数)
错误:
abc: {
immediate: true,
handler: () => {
console.log(this.abc);
},
},
修改成:
abc: {
immediate: true,
handler: function () {
console.log(this.abc);
},
}
更多推荐
已为社区贡献2条内容
所有评论(0)