今天小编给大家分享一下vue3中addRoute路由变化但页面未更新如何解决的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
解决办法,每次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路由变化但页面未更新如何解决”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注天达云行业资讯频道。