1.监听对象
watch: {
  'form.linkNum': {
    handler: function() {
      alert('我正在监听中')
    }
  }
},
watch: {
 'form.linkNum'(newValue, oldValue) {
   alert(oldValue)
   alert(newValue)
 }
}

监听字段不允许输入特殊字符

watch: {
    'form.comment': {
      deep: true,
      handler(val) {
        this.$nextTick(() => {
          const pat = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%&*()\-+={}|《》?:“”【】、;‘’,。、]/im
          if (pat.test(val)) {
            this.form.comment = val.slice(0, val.length - 1)
          }
        })
      }
    }
  },

监听整个表单Object

watch: {
    editForm: {
      handler(n, o) {
        // do something
      },
      deep: true// 深度监听父组件传过来对象变化
    }
  },

以后补充

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐