想必大家在平时开发的时候可能遇到这种需求,在打开该菜单页面的情况下,再次点击菜单需要刷新该组件(销毁再创建)。而vue自身如果路由不变的情况下是不会这样做的,那么只能使用一些骚操作了。1.在菜单的路由跳转上绑定一个随机query参数,例如时间戳或者随机数:
this.$router.push({

path:"/xxx",

query:{

t:Date.now(),

},
});
this.$router.push({

path:"/xxx",

query:{

t:Date.now(),

},
});该操作会触发路由改变,但是组件内的状态没有初始化,因为组件没有被重建。2.在路由容器上绑定key值:

大功告成,通过key值的变化去强制刷新该组件。补充知识:[vue-router] Duplicate named routes definition补充知识:补充知识:[vue-router] Duplicate named routes definition浏览器告警信息
[vue-router] Duplicate named routes definition: { name: “index”, path: “/index” }
[vue-router] Duplicate named routes definition: { name: “index”, path: “/index” }说明路由命名的name属性重复举 例: 举 例:
{ path: ‘', name: ‘index', redirect: ‘/fiibox/personHome' },
{ path: ‘', name: ‘index', redirect: ‘/fiibox/personHome' },改正:
{ path: ‘', name: ‘', redirect: ‘/fiibox/personHome' },
{ path: ‘', name: ‘', redirect: ‘/fiibox/personHome' },以上这篇vue相同路由跳转强制刷新该路由组件操作就是小编分享给大家的全部内容了,希望能给大家一个参考。