Vue多个路由复用同一个组件时造成跳转时公共组件created等方法不执行的解决方法

官方文档说明:https://router.vuejs.org/zh/guide/essentials/dynamic-matching.html

解决方案:

1).将公共组件的created方法放入到一个新的函数中,例如     init()

2).使用@Watch监控路由, @Watch($route)

3).在created和watch里面分别使用 init()函数即可

例如

@Watch('$route')
onRouteChange(to:stiring,from:string){
    this.init().then(){
    }.catch()
}
发布了60 篇原创文章 · 获赞 11 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/mianyao1004/article/details/102977292