监听 路由的to和from。
第一种全局监控,每次进入页面之前都会触发,可以根据需求而定操作。
router.js
router.beforeEach(){
//你的操作
}
第二种就是写在页面里面的,这种配合vuex,或者事件管理会更方便,当然这个也是根据需求而定。
data(){
return {}
},
computed{},
mounted{},
watch{
'$route' (to, from) {
console.log(to)
console.log(from)
}
}