Vue项目中通过watch监控对象中的某一属性

在Vue项目中的某一组件内,我需要监控data内某一对象的某一属性变化,已作处理;

组件data中的数据如下:

data:{
    return {
        pickedForm: {
            pickedDate: "",
            pickedInStation: "",
            pickedOutStation: ""
      },
    }
}

完成以上功能,只需要两步

1.在computed中定义一下方法:

computed: {
    dateChange() {
      return this.pickedForm.pickedDate;
    }
  },

2.在watch中监控computed中的方法

watch: {
    dateChange(newValue, oldValue) {
      console.log(newValue); //日期变化
        //处理方法
    }
  },

 

posted @ 2019-04-24 16:07  一捆铁树枝_james  阅读(77)  评论(0)    收藏  举报