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 read property of null vue3 Uncaught TypeError: Cannot read property 'created' of undefined,vue3報錯 Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解決方法 Vue 組件封裝發布到npm 報錯 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined Vue報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解決方法 bootstrap table 報錯 Uncaught TypeError: Cannot read property 'colspan' of undefined DataTable插件報錯:Uncaught TypeError: Cannot read property 'style' of undefined vue cli3/vue cli4開啟gzip打包報錯:TypeError: Cannot read property 'tapPromise' of undefined Vue 使用自定義組件時報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Uncaught TypeError: Cannot read property 'addEventListener' of null
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM