[vue] vue-router如何响应路由参数的变化?
watch
1.watch
2.在父组件的router-view上加个key
ickt-5:
路由 vue-router 面试题:
https://blog.csdn.net/Arthas_Xue/article/details/101024666
在父组件的router-view上加个key:
https://www.jianshu.com/p/802f357d9699
解决方案:
watch: {
$route(to, from){
if(to != from) {
console.log("监听到路由变化,做出相应的处理");
}
}
}
<router-view :key="$route.fullPath"></router-view>1.watch
2.导航守卫
干啥玩意?咋又给我发???
------------------ 原始邮件 ------------------
发件人: "WenJieLi1998"<[email protected]>;
发送时间: 2020年4月19日(星期天) 上午10:56
收件人: "haizlin/fe-interview"<[email protected]>;
抄送: "Coisini"<[email protected]>;"Comment"<[email protected]>;
主题: Re: [haizlin/fe-interview] [vue] vue-router如何响应路由参数的变化? (#383)
1.watch
2.导航守卫
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Most helpful comment
问题:为什么要响应参数变化?
解决方案:
<router-view :key="$route.fullPath"></router-view>> $route.fullPath 是完成后解析的URL,包含其查询参数信息和hash完整路径