下面是代碼,
這裏watch的意思是監聽
watch: {
$route: {
.....
}
}
//此處是監聽路由改變
獲取當前路由,如果路由路徑爲 / 或者 /authentication 或者 /release 或者 /mine 則讓data裏面的router_show的值爲ture
handler: function(val) {
....
},
//此處是處理方法-----當監聽到路由頁面發生改變後,要如何做,寫這裏
下面是完整代碼
export default {
data() {
return {router_show = false};
},
watch: {
$route: {
handler: function(val) {
if (val.path == '/home' || val.path == '/' || val.path == '/authentication' || val.path == '/release' || val.path == '/mine') {
this.router_show = true;
} else {
this.router_show = false;
}
},
// 深度觀察監聽,普通的watch方法無法監聽到對象內部屬性的改變,只有data中的數據才能夠監聽到變化,此時就需要deep屬性對對象進行深度監聽。
deep: true
}
}
};