vue watch 监测数据变化

  
- Create Cancel
export default {
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    }
  },
  watch: {
    newValue(nowVal, oldVal) {
      console.log(nowVal)
      console.log(oldVal)
      for (const key in nowVal) {
        if (nowVal[key] !== oldVal[key]) {
          console.log(key + `改变了,新值为` + nowVal[key])
          console.log('==================================')
          console.log(key + `改变了,旧值为` + oldVal[key])
          break
        } else {
          debugger
        }
      }
    },
    deep: true
  },
  computed: {
    newValue() {
      return { ...this.form }
    }
  },
  methods: {
    onSubmit() {
      this.$message('submit!')
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}

.line{
  text-align: center;
}

你可能感兴趣的:(vue watch 监测数据变化)