1.首先安裝vue-router ,在項目的文件夾中使用npm命令即npm install vue-router –save(提示:如果你在vue-cli腳手架工具中已經選擇安裝路由可以不用執行這一步)
2.在實戰中,一般路由放在src/router/index.js中具體操作如下
路由的配置,需要一個實例一個路由對象,然後在路由中配置中數組,具體如下,其中component組件需要自己import引入
new Router({
linkActiveClass: 'active',
routes: [
{
path: '/goods',
name: 'goods',
component: goods
},
{
path: '/comments',
name: 'comments',
component: comments
},
{
path: '/shops',
name: 'shops',
component: shops
}
]
})
3.然後在main.js中引入router文件夾下的index.js文件。
4.最後一步一定寫,就是在app.vue咧寫路由插座router-view
然後你就可以在router/index.js文件裏隨意配置你的路由了