在main.j中获取的this.$route.fullpath一直都是'/',因为给路由fullPath赋值是微任务,我们直接获取肯定只能拿到 根路由 “/”;
解决方案:
1.给路由fullPath赋值是微任务,那么只需要通过宏任务获取fullPath就可以了,
setTimeout(() => {
console.log(this.$route.fullPath)
}, 2000)
this.$router.onReady(() => {
console.log(this.$route.path)
});
参考
https://blog.csdn.net/m0_50929144/article/details/115053134
https://www.jianshu.com/p/bf0e2cf2be91
https://www.jianshu.com/p/bf0e2cf2be91