vue

vue如何切换路由

养鱼的猫咪
954
2021-05-12 09:51:42
栏目: 编程语言

在vue中切换路由的方法:1.新建项目,引入vue和vue-router;;2.使用Vue.use方法注册路由;3.定义路由;4.配置路由;5.使用el-menu-item标签设置路由点击切换;


vue如何切换路由

具体步骤如下:

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>

0
看了该问题的人还看了