网络编程
位置:首页>> 网络编程>> JavaScript>> vue element-ui实现动态面包屑导航

vue element-ui实现动态面包屑导航

作者:一入坑不回头  发布时间:2024-05-02 17:11:36 

标签:vue,面包屑,导航

vue element-ui动态面包屑导航,供大家参考,具体内容如下

直接上代码

一、template代码


// 这是单独的组件
<template>
<el-breadcrumb separator-class="el-icon-arrow-right">
// 首页我是写死的,其他的遍历出来
<el-breadcrumb-item :to="{ name: 'home' }">首页</el-breadcrumb-item>
// 因为路由是后台返回的,所以取title是按照后台格式来取的
<el-breadcrumb-item v-for="(item, index) in breadList" :key="index">{{
 item.meta.title
}}</el-breadcrumb-item>
</el-breadcrumb>
</template>

二、script代码


export default {
// 初始化数据对象
data() {
return {
 breadList: []
};
},
// 监听属性
watch: {
// 监听路由
$route(val) {
 // 调用获取路由数组方法
 this.getBreadList(val);
}
},
// 自定义事件
methods: {
/**
 * @description 获取路由数组
 * @params val 路由参数
 * @author tw
 */
getBreadList(val) {
 // 过滤路由matched对象
 if (val.matched) {
 let matched = val.matched.filter(item => item.meta && item.meta.title);
 // 拿到过滤好的路由v-for遍历出来
 this.breadList = matched;
 }
}
}
}

三、css代码

css样式是放在一个单独的样式文件夹里面


/* 面包屑导航 */
.el-breadcrumb {
@include ptrbl(16px,16px,16px,16px);
box-sizing: border-box;
background: $white;
border-bottom: 1px solid #EEE;
}

来源:https://blog.csdn.net/weixin_45817240/article/details/103641703

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com