這個報錯的根源就是vue-router組件,錯誤內容翻譯一下是: Avoided redundant navigation to current location === 避免冗余導航到當前位置
這個問題的解決方案就是屏蔽它,就是重寫vue-router的push方法,不影響正常使用
在 Vue.use(VueRouter的時候),前面加上這一句即可
const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function(location) { return originalPush.call(this, location).catch(err => err) }
主要的作用就是把err給屏蔽了,不進行輸出了,頁面看不到這個錯誤,但是不影響使用