Vue.js监听事件

普通监测

vue中的监听事件非常简单,因为双向绑定的缘故,我们只需要对值name进行监听,触发dataload事件

data() {
    return {
        name:'',   
    }
},
watch:{
    'name':'dataload',//或者下面的方法
    name(newValue, oldValue) {
        alert(newValue)
    }

},
methods:{
    dataload(){
        alert(this.name);
    }
}

对象里的属性进行监测

data() {
  return {
    person: {
            name:'',
        age:'',
    }   
    }
},
watch:{
    'person.name':{
            handler:'showName',
            // 深度观察
            deep:true
	},
},
methods: {
	showName(){
	    alert(this.person.name);
    }
}
原文地址:https://www.cnblogs.com/CurryZhang/p/7550513.html