Vue 打包后報錯 Uncaught TypeError: Cannot redefine property: $router


原因:就如報錯提示所描述的,不能重新定義$router,說明是重復定了$router。通常是因為在項目中安裝了vue-router的依賴並且用Vue.use()使用了vue-router,還在index.html頁面引入了vue-router.js文件。

解決方法有兩種:

  1. 去掉index.html中的vue-router.js文件的引入。如果沒有使用externals的話可以直接使用這種方法。

  2. 刪除vue-router的依賴,包括依賴包和package.json中的vue-router。使用了externals來外部引入vue-router的話則用這種方法。

提示:從vue-router.js文件引入的router對象名為VueRouter,新建router對象是 new VueRouter()。

 

參考資料:vue路由器報錯


免責聲明!

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



猜您在找 Vue 打包后報錯 Uncaught TypeError: Cannot redefine property: $router vue報錯 Uncaught TypeError: Cannot read property ‘children ’ of null vue報錯 Uncaught TypeError: Cannot read property of null vue報錯TypeError: Cannot read property of undefined 或 Uncaught TypeError: this.myMethod is not a function vue3 Uncaught TypeError: Cannot read property 'created' of undefined,vue3報錯 Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' vue報錯getVueAllUser:67 Uncaught TypeError: Cannot read property 'userId' of undefined Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解決方法
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM