Vue-Router:Uncaught (in promise) 報錯處理


  • Vue-router≥3.0版本中,路由回調形式已經改成了Promise API形式,返回一個Promise

  • 在相同路由轉跳並且沒有捕獲錯誤時會在控制打印如下信息:

  • 方法1:可在全局配置一個catch捕捉錯誤:

    我是直接寫在 router > index.js 文件中

      // 包裝路由函數,添加處理錯誤方法;
          const originalPush = VueRouter.prototype.push;
          VueRouter.prototype.push = function(location) {
              return originalPush.call(this, location).catch(err => err);
          };
    
  • 方法2:在調用路由函數時捕獲錯誤:

  • 方法3:使用3.0以下版本。


免責聲明!

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



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