使用watch监听路由变化和watch监听对象

一、watch监听路由变化

解决办法:

export default{

data(){

return{}

},

watch:{

"$route":"getPath"  // 监听事件

},

methods:{

getPath(){

let path = this.$roune.path;    //或得当前路径

进行逻辑判断

}

}

}

二、watch监听对象

例子:

form.region" placeholder="请选择">
                            v-for="item in rootCategory" :key="item.id"
                   :label="item.name"
                   :value="item.id">
         



export default{

data(){

return{ 

form:{

region:""

}

}

},

watch:{

'form.region':function(newValue,oldValue){

console.info(newValue);

console.info(oldValue);

}

}

}



你可能感兴趣的:(vue,watch)