美文网首页
Vue.js监听事件

Vue.js监听事件

作者: 高调的小丑 | 来源:发表于2017-08-03 11:04 被阅读101次

普通监测

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);
    }
}

相关文章

网友评论

      本文标题:Vue.js监听事件

      本文链接:https://www.haomeiwen.com/subject/ofaulxtx.html