钩子只有 onBeforeRouteUpdate 和 onBeforeRouteLeave
钩子只有 onBeforeRouteUpdate 和 onBeforeRouteLeave
|
weimo383Dec 23, 2021
1
你只能监听路由变化,每次一变化就把他存进 store 里
|
|
sualvinDec 23, 2021
3
beforeRouteEnter 这个钩子里面的 from 参数拿不到吗?我看 4 的文档也有这个钩子啊
|
|
5
@sualvin #3 好像 script setup 的用法不一样
这是正常的用法 ```vue setup() { console.log('SETUP') }, beforeRouteEnter(to, from, next) { // Do something next({ path: '/foo' }); // Go somewhere else if necessary next(); // Or stay here } ``` |
|
daolanflerDec 23, 2021
8
|
|
daolanflerDec 23, 2021
9
@daolanfler 看错了,好像 setup 里面不支持 beforeRouteEnter ....
|
|
lin07huiDec 23, 2021
10
避免当前页面去获取其它页面的数据,刷新一下其它页面就没了
|
|
lx000377Dec 23, 2021
11
在全局前置守卫或者后置钩子里把历史路由放在新路由的 meta 里,组件里用 route.meta.lastPath 读取
代码: router.afterEach((to, from) => { if (from) { to.meta.lastPath = from.fullPath; } }); 如图 https://s2.loli.net/2021/12/23/eErqCDp4Vs1oNZJ.png |