如果您的需要只是由于路由参数更改而“刷新”组件,请尝试以下操作:
// define a watcher
watch: {
"$route.params.id"(val) {
// call the method which loads your initial state
this.find();
},
},
Run Code Online (Sandbox Code Playgroud)
其中“id”来自 /myroute/:id 和 find() 是一个常规方法。
选项之一是在 RouterView 上使用 key:
<RouterView :key="whenThisVarChangeRouterViewWillBeRemounted" />
Run Code Online (Sandbox Code Playgroud)
如果您不想在每次路由器视图更改时重新加载,请确保将密钥放在合理的位置,否则您可以使用:
:key="$route.fullPath"
Run Code Online (Sandbox Code Playgroud)
这将保证每次更改路径时都会重新安装。
您可以使用“beforeEnter”文档。
{
path: '/foo', component: Foo,
beforeEnter: (to, from, next) => {
/*
todo check if to === from
Warning!: location.reload() completely destroy all vuejs stored states
*/
window.location.reload()
return next()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5027 次 |
| 最近记录: |