Vue侦听器watch获取this报undefined

1,559 阅读1分钟

错误代码

watch: {
  data: {
    handler: (newVal) => {
      this.info = newVal
    },
    deep: true
  }
},

修正后代码

watch: {
  data: {
    handler: function (newVal) {
      this.info = newVal
    },
    deep: true
  }
},

原因

总的来说还是this指向问题,可以查看普通函数与箭头函数this指向问题