vue項目中有很多地方都是跳到同一個頁面,只是參數(shù)不同,根據(jù)不同參數(shù)來做處理,一開始發(fā)現(xiàn)只參數(shù)變而路由不變沒辦法檢測到,想想百度了下是否能監(jiān)聽路由參數(shù)的變化,最終用下面的方法試了下,發(fā)現(xiàn)可行
watch:{
'$route.params'(newval, oldval) {
let indexarr = this.$route.params.indexObj.split('-');
let fatherIndex = Number(indexarr[0]);
this.pname = menuComponents[fatherIndex].pname;
this.menuList = menuComponents[fatherIndex].children;
this.imgUrl = this.imgs[fatherIndex];
this.showNewscontent(Number(indexarr[1]))
}
}