Vue router / Element 重復點擊導航路由報錯解決方法


雖然此報錯並不會影響項目運行,但是作為一個強迫症的碼農的確受不了error,解決方法如下:

方法1:在項目目錄下運行 npm i vue-router@3.0 -S 將vue-router改為3.0版本即可;
方法2:若不想更換版本解決方法:
在router.js中加入以下代碼就可以

記住插入的位置

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 如果你的改了push還是沒有生效,可以考慮改replace方法 

// 修改路由replace方法,阻止重復點擊報錯

const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM