在vue中切換路由的方法:1.新建項目,引入vue和vue-router;;2.使用Vue.use方法注冊路由;3.定義路由;4.配置路由;5.使用el-menu-item標簽設置路由點擊切換;
具體步驟如下:
1.首先,在新建一個html項目,并在項目中引入vue和vue-router;
import Vue from 'vue'
import Router from 'vue-router'
2.vue和vue-router引入好后,在項目中使用Vue.use方法注冊路由;
Vue.use(Router)
3.路由注冊好后,在頁面中分別定義三個路由于切換;
export default {
name:"AComponent"
}
export default {
name:"BComponent"
}
export default {
name:"CComponent"
}
4.路由定義好后,在項目中執行以下代碼配置路由;
{
path: '/index',
name: 'index',
component: resolve => require(['@/components/routerTab/index.vue'],resolve),
children:[
{
path:'aaa',
component: resolve => require(['@/components/routerTab/A.vue'], resolve)
},
{
path: 'bbb',
component: resolve => require(['@/components/routerTab/B.vue'],resolve)
},
{
path: 'ccc',
component: resolve => require(['@/components/routerTab/C.vue'],resolve)
}
]
}
5.最后,路由配置好后,使用el-menu-item標簽設置路由點擊切換即可;
<el-menu-item index="/index/aaa">A</el-menu-item><el-menu-item index="/index/bbb">B</el-menu-item>
<el-menu-item index="/index/ccc">C</el-menu-item>