Vue侦听器watch获取this报undefined

2020-01-08  本文已影响0人  MuRongXDB

错误代码

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

修正后代码

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

原因

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

原文链接:https://www.imuboy.cn/

上一篇 下一篇

猜你喜欢

热点阅读