如何在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中使用面包屑导航组件,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注恰卡编程网行业资讯频道。
目录
推荐阅读
-
vue表格组件教程学习(vue proxytable只能在开发环境跨域吗)
vueproxytable只能在开发环境跨域吗?跨域问题来源于JavaScript的同源策略,即只有协议主机名端口号(如...
-
Vue组件的自定义事件和全局事件总线怎么使用
-
vue中消息订阅与发布如何使用
vue中消息订阅与发布如何使用这篇文章主要介绍“vue中消息订阅与...
-
Vue显示图片的方式有哪些
-
vue引入静态jquery报错如何解决
vue引入静态jquery报错如何解决这篇文章主要介绍“vue引入...
-
vue-cropper怎么实现裁剪图片
-
怎么用Vue+NodeJS实现大文件上传
-
Vue如何实现简易跑马灯效果
-
Vue怎么指定不编译的文件夹和favicon.ico
Vue怎么指定不编译的文件夹和favicon.ico这篇文章主要介...
-
Vue中的插槽怎么使用
0 条评论
本站已关闭游客评论,请登录或者注册后再评论吧~