前段时间 Vue升了2 相应vue-router,vue-cli 也升了2,最近我也在学,坑不少,加上wepack 和ESlint 的语法,差点奔溃,
废话不说上代码
1 import Vue from 'vue' 2 import App from './App' 3 import VueRouter from 'vue-router' 4 // 引入子组件到路由 5 import goods from './components/goods/goods.vue' 6 import seller from './components/seller/seller.vue' 7 import ratings from './components/ratings/ratings.vue' 8 9 Vue.config.productionTip = false 10 11 Vue.use(VueRouter) 12 13 let router = new VueRouter({ 14 routes: [ //!!!! 注意这里 是 routes 不是 routers 没有 'r' 15 {path: '/goods', component: goods}, 16 {path: '/seller', component: seller}, 17 {path: '/ratings', component: ratings} 18 ] 19 }) 20 21 /* eslint-disable no-new */ 22 new Vue({ 23 el: '#app', 24 template: '<App/>', 25 components: { App }, 26 router: router 27 })构造函数 VueRouter 里面的是 routes ,而不是routers ,切记切记~~~
转载于:https://www.cnblogs.com/Chen-J/p/6534648.html