Vue2+element-ui使用面包屑导航的正确姿势

1、面包屑导航栏布局
Vue2+element-ui使用面包屑导航的正确姿势
代码:

<template>
    <!--面包屑导航页签-->
    <div style="padding: 25px 0;flex: 1">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item v-for="breadCrumbItem in breadCrumbList" :key="breadCrumbItem.path" :to="breadCrumbItem.path">
                {{breadCrumbItem.meta.title}}
            </el-breadcrumb-item>
        </el-breadcrumb>
    </div>
</template>

在使用面包屑导航的vue文件里添加:

<script>
    export default {
        computed: {
            breadCrumbList() {
                return this.$route.matched;
            }
        },
    }
</script>

2、index.js里面配置路由:

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    //主页
    {
        path: '/',
        component: () => import(/* webpackChunkName: "about" */ '../views/Manage.vue'),
        redirect: "/home",  /*请求'/manage'时重定向到/manage/home路由*/
        meta: {title: ""},  //定义其他属性
        children: [
            {
                path: "home", name: '主页', meta: {title: "主页"}, component: () => import("../views/Home")
            },
        ]
    },
    //系统管理
    {
        path: '/sys',
        component: () => import(/* webpackChunkName: "about" */ '../views/Manage.vue'),
        meta: {title: "系统管理"},  //定义其他属性
        redirect: "/home",
        //用户界面子路由
        children: [
            {
                path: "user", name: '用户管理', meta: {title: "用户管理"}, component: () => import("../views/User")
            },
            {
                path: "order", name: '订单管理', meta: {title: "订单管理"}, component: () => import("../views/Order")
            }
        ]
    }
]
const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
export default router

3、侧边导航栏样式
Vue2+element-ui使用面包屑导航的正确姿势
代码:

<template>
	<el-menu>
		<!--主页-->
        <el-menu-item index="/">
            <template slot="title"><i class="el-icon-s-home"></i>
                <span slot="title">主页</span>
            </template>
        </el-menu-item>
        <!--系统菜单-->
        <el-submenu index="/sys">
            <template slot="title"><i class="el-icon-menu"></i>
                <span slot="title">系统管理</span>
            </template>
            <el-menu-item index="/sys/user"><i class="el-icon-s-custom"/>用户管理</el-menu-item>
            <el-menu-item index="/sys/order"><i class="el-icon-s-check"/>订单管理</el-menu-item>
        </el-submenu>
	</el-menu>
</template>
上一篇:一、手把手教你 Vue2+Ts


下一篇:HttpServletResponse类