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

vue項目原本是用0.x版本的vue-router,但是去報出:Cannot read property 'component' of undefined

這是因為版本問題,由于vue2刪除了vue1的內部指令,而vue-router1.x依賴vue的一個內部指令

研究了下vue-router官網,小白我用了接近一天來解決問題,最后我將vue-router改為2.2.0版本

1.打開package.json? 將"dependencies"中的? ?"vue-router"版本改為:"^2.2.0"

2.npm install

3.在App.vue中

改為 商品

(這個坑了我很久)

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}

]

//創(chuàng)建 router 實例,然后傳 `routes` 配置

var router=new VueRouter({

linkActiveClass: 'active',

routes

});

//=>

是ES6的箭頭語法

new Vue({

el:'#app',

router,

render:h=>h(App)

})

vue-router官網:https://router.vuejs.org

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容