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 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