如何在vue中使用面包屑导航组件

本篇文章为大家展示了如何在vue中使用面包屑导航组件,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

vue的面包屑导航组件

如何在vue中使用面包屑导航组件

用来将其放到navbar中;

Breadcrumb/index.vue

<template>
<el-breadcrumbclass="app-breadcrumb"separator="/">
<transition-group>
<el-breadcrumb-itemv-for="(item,index)inlevelList":key="item.path"v-if="item.meta.title">
<spanv-if='item.redirect==="noredirect"||index==levelList.length-1'class="no-redirect">{{item.meta.title}}</span>
<router-linkv-else:to="item.redirect||item.path">{{item.meta.title}}</router-link>
</el-breadcrumb-item>
</transition-group>
</el-breadcrumb>
</template>
<script>
exportdefault{
name:"idnex",
data(){
return{
levelList:null
}
},
created(){
this.getBreadcrumb()
},
watch:{
$route(){
this.getBreadcrumb()
}
},
methods:{
getBreadcrumb(){
letmatched=this.$route.matched.filter(item=>item.name)//$route.matched将会是一个包含从上到下的所有对象(副本)。
constfirst=matched[0]
if(first&&first.name!=='dashboard'){//$route.name当前路由名称;$route.redirectedFrom重定向来源的路由的名字
matched=[{path:'/dashboard',meta:{title:'dashboard'}}].concat(matched)
}
this.levelList=matched
}
}
}
</script>
<stylerel="stylesheet/scss"lang="scss"scoped>
.app-breadcrumb.el-breadcrumb{
display:inline-block;
font-size:14px;
line-height:50px;
margin-left:10px;
.no-redirect{
color:#97a8be;
cursor:text;
}
}
</style>

ps:下面在看下一段代码Vue 面包屑导航

样式采用的是element ui 中的面包屑设置的,

<template>
<el-breadcrumb>
<el-breadcrumb-itemseparator='/'v-for="(item,index)inbreadlist":key='index':to="{path:item.path}">{{item.meta.CName}}
</el-breadcrumb-item>
</el-breadcrumb>
</template>
js部分
<script>
exportdefault{
data(){
return{
breadlist:''
}
},
created(){
this.getBread();
},
methods:{
getBread(){
this.breadlist=this.$route.matched;
this.$route.matched.forEach((item,index)=>{
//先判断父级路由是否是空字符串或者meta是否为首页,直接复写路径到根路径
item.meta.CName==='首页'?item.path='/':this.$route.path===item.path;
});
}
},
watch:{
$route(){
this.getBread();
}
}
}
</script>

上述内容就是如何在vue中使用面包屑导航组件,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注恰卡编程网行业资讯频道。

发布于 2021-02-24 07:34:39
收藏
分享
海报
0 条评论
179
上一篇:如何在javascript中对数据类型进行检测 下一篇:如何在python项目中使用内置函数
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码