解决:Cannot read property ‘component‘ of undefined ( 即 vue-router 0.x 转化为 2.x)
前些天發(fā)現(xiàn)了一個(gè)巨牛的人工智能學(xué)習(xí)網(wǎng)站,通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家。點(diǎn)擊跳轉(zhuǎn)到教程。
vue項(xiàng)目原本是用0.x版本的vue-router,但是去報(bào)出:Cannot read property 'component' of undefined
這是因?yàn)榘姹締?wèn)題,由于vue2刪除了vue1的內(nèi)部指令,而vue-router1.x依賴vue的一個(gè)內(nèi)部指令
研究了下vue-router官網(wǎng),小白我用了接近一天來(lái)解決問(wèn)題,最后我將vue-router改為2.2.0版本
1.打開package.json??將"dependencies"中的???"vue-router"版本改為:"^2.2.0"
2.執(zhí)行:
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';
//使用模塊化機(jī)制編程,導(dǎo)入Vue和VueRouter,要調(diào)用 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 實(shí)例,然后傳 `routes` 配置
var router=new VueRouter({
linkActiveClass: 'active',
??routes
});
//=> 是ES6的箭頭語(yǔ)法
new Vue({
el:'#app',
router,
render:h=>h(App)
})
vue-router官網(wǎng):https://router.vuejs.org
---------------------?
轉(zhuǎn)自:https://blog.csdn.net/m0_37754657/article/details/71269988?
?
總結(jié)
以上是生活随笔為你收集整理的解决:Cannot read property ‘component‘ of undefined ( 即 vue-router 0.x 转化为 2.x)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 简单的OPC与C#通讯,别想复杂了
- 下一篇: 开发框架-概念