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