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()。

https://www.cnblogs.com/mengyouyouyou/p/10936171.html


免責聲明!

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



猜您在找 vue報錯 Uncaught TypeError: Cannot read property ‘children ’ of null Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' vue報錯getVueAllUser:67 Uncaught TypeError: Cannot read property 'userId' of undefined 前台報錯:Uncaught TypeError: Cannot read property '0' of null js 報錯 Uncaught TypeError: Cannot read property 'trim' of undefined VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined vue-cli4創建項目導入elementUI,瀏覽器報錯Uncaught TypeError: Cannot read property ‘prototype‘ of undefined Uncaught TypeError: Cannot read property 'trim' of undefined Uncaught TypeError: Cannot read property 'filter' of null Uncaught TypeError: Cannot read property 'nodeType' of undefined
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM