vuejs如何监控对象中某个属性值的变化。

 new Vue({
      el: '#demo',
      data: {
        things: [{foo:1}, {foo:2}]
      },
      watch: {
        things: {
          handler: function (val, oldVal) {
            alert('a thing changed')
          },
          deep: true
        }
      },
      methods: {
        change: function (item) {
          console.log(item)
          //item.a = 2
          this.$set('item.a',2)
          //item.a属性并无变化,应该怎么样赋值?
        }
      }
    })

具体的看下嘛代码调试

链接描述

阅读 8.4k
2 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题