Cannot read property 'component' of undefined 即vue-router 0.x转化为2.x

Posted web小白需努力

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cannot read property 'component' of undefined 即vue-router 0.x转化为2.x相关的知识,希望对你有一定的参考价值。

原文链接:http://blog.csdn.net/m0_37754657/article/details/71269988

由于vue版本为1.0,没有一些vue-router指令;因而需要vue-router2.0解决。

1.打开package.json  将"dependencies"中的   "vue-router"版本改为:"^2.2.0"

2.npm install 

3.在App.vue中

        <a v-link="{path:‘/goods‘}"></a>

改为 <router-link to="/goods">商品</router-link> 

(这个坑了我很久)

4.然后在main.js中(我的main.js是这样的【2.2.0版本】)

import Vue from ‘vue‘;
import VueRouter from ‘vue-router‘;
import App from ‘./App‘;
import goods from ‘./components/goods/goods‘;
import seller from ‘./components/seller/seller‘;
import ratings from ‘./components/ratings/ratings‘;


//使用模块化机制编程,導入Vue和VueRouter,要调用 Vue.use(VueRouter)
Vue.use(VueRouter);

//定义路由
var routes=[
{path:‘/‘,redirect: ‘/goods‘}, 
{path:‘/goods‘,component:goods},
{path:‘/ratings‘,component:ratings},
{path:‘/seller‘,component:seller}
]

//创建 router 实例,然后传 `routes` 配置
var router=new VueRouter({
linkActiveClass: ‘active‘,
  routes
});
//=> 是ES6的箭头语法
new Vue({
el:‘#app‘,
router,
render:h=>h(App)
})

以上是关于Cannot read property 'component' of undefined 即vue-router 0.x转化为2.x的主要内容,如果未能解决你的问题,请参考以下文章

Uncaught TypeError: Cannot read property 'addEventListener'

Uncaught TypeError: Cannot read properties of undefined (reading 'getUserMedia')

axios报错: Cannot read property 'protocol' of undefined ....

解决报错Cannot read property 'forceUpdate' of undefined

VUE TypeError: Cannot read property 'validate' of undefined

Cannot read property 'map' of undefined