vue中路由的使用
1.先在终端安装路由 vue install vue-router --save-dev
2.在main.js引入路由
import VueRouter from 'vue-router'
3.在main.js中使用路由
Vue.use(VueRouter)
4.配置路由
const routes=[
{path:"/",redirect:"/goods"},
{path:"/goods",component:Goods},
{path:"/ratings",component:Ratings},
{path:"/seller",component:Seller}
]
5.实例化router
const router=new vueRouter({
routes
})
6.把router放到vue的实例化里面
new Vue({
el:"#app",
router,
components:{App},
template:"<App/>"
})