前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
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中
????????<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)
})
vue-router官網:https://router.vuejs.org
---------------------?
轉自:https://blog.csdn.net/m0_37754657/article/details/71269988?
?