Vue.js搭建路由报错 router.map is not a function,Cannot read property ‘component’ of undefined

时间:2021-09-11 09:05:12

综述:一开始我遇到的问题是,router.map is not a function,然后我在网上查,就安装了npm install vue-router@0.7.13兼容1.0版本,就没有报这个错了,但是又报了一个新错Cannot read property ‘component’ of undefined,然后看了你的这篇,就安装了npm install vue-router@next,就没有报Cannot read property ‘component’ of undefined的错了

 

错误:

Vue.js搭建路由报错 router.map is not a function,Cannot read property ‘component’ of undefined

解决办法:

2.0已经没有map了,使用npm install vue-router@0.7.13 命令兼容1.0版本vue

Vue.js搭建路由报错 router.map is not a function,Cannot read property ‘component’ of undefined

再引入文件

Vue.js搭建路由报错 router.map is not a function,Cannot read property ‘component’ of undefined

 ****************************************************
上面解决之后可能又会出现
问题  Cannot read property ‘component’ of undefined

原因

版本问题,由于vue2删除了vue1的内部指令,而vue-router1.x依赖vue的一个内部指令。

这上面如果是1.x版本,会读取Vue.internalDirectives.component这个属性,而实际上vue2根本没有Vue.internalDirectives,所以导致undefined。

解决方法

vue-router-next 
到这里下载即可,或者

npm install vue-router@next


原文链接:http://blog.csdn.net/sunOpar/article/details/52471582
原文链接:http://blog.csdn.net/gaoxiaoba/article/details/52813867