写法一:app
methods:{ //监听isMD upProp(){ if(this.isMD){//若是isMD等于true 就把storeManagerName赋值给isStoreManagerName this.isStoreManagerName='storeManagerName'; }else{ this.isStoreManagerName=''; } } }, watch:{ 'isMD':'upProp' }
写法二:this
var vm = new Vue({ el:'#app' , data:{ name:'' } }) //使用实例调用watch方法,这种是在实例外调用,而第一种是在实例里面调用,效果都是同样的 vm.$watch('name',()=>{ console.log("数据改变了"); })