Vue + elementUI实现动态面包屑

后台接口输出json:

{
  "success": true,
  "code": 20000,
  "message": "成功",
  "data": {
    "menus": [
      {
        "mid": "1",
        "title": "数据统计",
        "icon": "el-icon-s-data",
        "path": "/welcome/",
        "parentMid": "0",
        "createTime": "2020-10-14 10:37:46",
        "updateTime": "2020-10-14 10:37:49",
        "children": []
      },
      {
        "mid": "2",
        "title": "用户管理",
        "icon": "el-icon-s-custom",
        "path": "/user",
        "parentMid": "0",
        "createTime": "2020-10-14 10:39:31",
        "updateTime": "2020-10-14 10:39:32",
        "children": [
          {
            "mid": "21",
            "title": "用户列表",
            "icon": "el-icon-document",
            "path": "/user/",
            "parentMid": "2",
            "createTime": "2020-10-14 10:57:12",
            "updateTime": "2020-10-14 10:57:13"
          },
          {
            "mid": "22",
            "title": "用户添加",
            "icon": "el-icon-edit-outline",
            "path": "/user/save/",
            "parentMid": "2",
            "createTime": "2020-10-14 10:57:15",
            "updateTime": "2020-10-14 10:57:17"
          }
        ]
      }
    ]
  }
}

ElementUI面包屑:

<!-- 面包屑 -->
<el-breadcrumb separator-class="el-icon-arrow-right">
	<el-breadcrumb-item :to="{ path: '/welcome'}" @click="clearRouter">首页</el-breadcrumb-item>
	<el-breadcrumb-item v-for="item in breadcrumbList" :key="item.path">
		{{item.title}}
	</el-breadcrumb-item>
</el-breadcrumb>

computed计算属性:

computed: {
	// 动态面包屑
	breadcrumbList() {
		let breadcrumbs = []
		// 获取的菜单列表
		let menuList = this.menuList
		// 获取面包屑路由菜单对象
		this.indexBreadcrumbs.map(item => {
			for (let i = 0; i < menuList.length; i++) {
				// 如果是有二级菜单
				if (menuList[i].children !== undefined && menuList[i].children.length > 0 && item == menuList[i].path) {
					breadcrumbs.push(menuList[i])
					continue
				}
				// 如果没有二级菜单
				else if(menuList[i].children !== undefined && menuList[i].children.length == 0 && item == menuList[i].path) {
					breadcrumbs.push(menuList[i])
					break
				}
				// 如果是二级菜单
				else {
					for(let j = 0; j < menuList[i].children.length; j++) {
						if (item == menuList[i].children[j].path) {
							breadcrumbs.push(menuList[i].children[j]);
							break
						}
					}
				}
			}
		})
		return breadcrumbs
	}
}

话不多说,来看最终效果:
效果图

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值