vue router-view解决 router-link跳转不刷新页面问题

问题:router-link跳转到其他页面,页面不刷新

跳转前路由:http://localhost:8080/#/xxx?id=n&from=yyy

跳转后路由:http://localhost:8080/#/xxx?id=n&type=2

问题原因:

以上路由path:http://localhost:8080/#/xxx

跳转前fullPath:http://localhost:8080/#/xxx?id=n&from=yyy

跳转后fullPath:http://localhost:8080/#/xxx?id=n&type=2

由于跳转前的路由path跟跳转后的路由path是一样的,所以vue会复用组件,不会刷新组件

解决方法:

设置 router-view 的 key 属性值为 $route.fullPath

<router-view :key='$route.fullPath'>

通过绑定一个fullPath,可以识别当前页面路由的完整地址,当地址发生改变(包括参数改变)则重新

渲染页面(例如动态路由参数的变化)

跳转前路由fullPath跟跳转后的路由fullPath不一样,会刷新页面。
 

猜你喜欢

转载自blog.csdn.net/m0_73533910/article/details/131811833