Home  >  Article  >  Web Front-end  >  watch listens for routing changes and watch listening objects (detailed tutorial)

watch listens for routing changes and watch listening objects (detailed tutorial)

亚连
亚连Original
2018-06-04 16:15:273573browse

Below I will share with you an example of using watch to monitor routing changes and watch monitoring objects. It has a good reference value and I hope it will be helpful to everyone.

1. Watch to monitor routing changes

Solution:

export default{
data(){
return{}
},
watch:{
"$route":"getPath" // 监听事件
},
methods:{
getPath(){
let path = this.$roune.path; //或得当前路径
进行逻辑判断
}
}
}

2. Watch monitoring object

Example:

<el-select v-model="form.region" placeholder="请选择">
   <el-option
     v-for="item in rootCategory" :key="item.id"
     :label="item.name"
     :value="item.id">
   </el-option>
</el-select>
export default{
data(){
return{ 
form:{ 
region:""
}
}
},
watch:{
&#39;form.region&#39;:function(newValue,oldValue){
console.info(newValue);
console.info(oldValue);
}
}
}

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

p5.js introductory tutorial ball animation sample code

Angularjs Promise instance detailed explanation

Detailed explanation of the five methods of exporting Excel using JS


##

The above is the detailed content of watch listens for routing changes and watch listening objects (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn