溫馨提示×

vue如何監聽路由

vue
養魚的貓咪
1386
2021-05-12 19:56:43
欄目: 編程語言

在vue中監聽路由的方法有:1.使用watch方法監聽;2.使用watch方法監聽路由變化,并獲取路由信息;3.使用beforeEach方法全局監聽;4.使用beforeRoute方法在組件內部監聽

vue如何監聽路由

具體方法如下:

1.使用watch方法監聽路由

watch:{

$route(to,from){

console.log(from.path);

console.log(to.path);

}

}

2.使用watch方法監聽路由變化,并獲取路由信息

watch:{

$route:{

handler(val,oldval){

console.log(val);

console.log(oldval);

},

deep: true

}

}

3.使用beforeEach方法全局監聽路由

router.beforeEach((to, from, next) => {

console.log(to);

next();

});

export default router

4.使用beforeRoute方法在組件內部監聽路由

beforeRouteEnter (to, from, next) {

}

beforeRouteUpdate (to, from, next) {

}

beforeRouteLeave (to, from, next) {

}

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女