原文链接: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)
})