vue3中addRoute路由变化页面未刷新问题解决

Tina ·
更新时间:2024-09-20
· 1031 次阅读

路由变化了但页面没有更新

按着vue2的写法写vue3 发现路由变化了但页面没有更新

搜索了半天没有解决办法。

想了半天觉得是重复用同一个对象,vue为了节约性能就没有新建, 被vue3给优化了

解决办法,每次addRoute时 深复制组件对象

import time from "../views/time" function copyObj(obj) { if (typeof obj == "object") { if (Array.isArray(obj)) { let arr = []; for (let item of obj) { arr.push(Object.assign(copyObj(item))); } return arr; } else if (obj == null) { return null; } else { let obj1 = {}; for (let index in obj) { obj1[index] = copyObj((obj[index])); } return obj1; } } else if (typeof obj == "function") { return Object.assign(obj); } else if (typeof obj == undefined) { return undefined; } else { return obj; } } window.pushTime = function () { let t = new Date().getTime(); let path = `/time/${t}`; time = copyObj(time) this.$router.addRoute({ path, name: path, component: time, }); this.$router.push({ path, }); }

以上就是vue3中addRoute路由变化但页面未更新问题解决的详细内容,更多关于vue3 addRoute页面刷新的资料请关注软件开发网其它相关文章!



VUE

需要 登录 后方可回复, 如果你还没有账号请 注册新账号