关于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);
	},
},

修改结果为:

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);
   },
}

版权声明:本文为weixin_46684929原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。