1问题描述
页面 A->B 从浏览器回退到 A ,然后 A->C ,然而C 的页面内容是B的,C页面的 路由地址和参数都是对的。
2.解决方法,我是重新刷新一下,但是这个不好有刷新的痕迹。
1)用watch监控 $route 监控不到 ,都是空的
watch:{
$route(to, from) {
console.log("----------");
console.log(to);
console.log(from);
this.$router.go(0);
}
}
2)用 beforeRouteEnter 钩子函数,用watch 监控 data对象中 fullPath 的变化
beforeRouteEnter(to, from, next) {
next(vm => {
// 通过 `vm` 访问fetchData,将query参数name,传递过去,进行逻辑处理
// debugger
// console.log(to)
// console.log(from)
// console.log(vm.$route); //有值
// next()
if (from.fullPath === "****") { //关键判断这里区别,自己刷新是 /
vm.fullpath = from.fullPath;
this.$router.go(0);
}
// vm.fetchData(vm.$route.query.name);
});
},
//监听变化
watch: