• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

详解基于iview-ui的导航栏路径(面包屑)配置

vue 搞代码 4年前 (2022-01-08) 21次浏览 已收录 0个评论

这篇文章主要介绍了详解基于iview-ui的导航栏路径(面包屑)配置,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

起因

上家公司的后台管理系统都是刷表刷出来的,所用很久很久没写后台管理系统了。换了工作后总算要开始捣腾router了,很久没用都快忘光了,所以把一些通用的模块记录一下,也分享给需要的朋友们。

经过

 //router.js let routes = [ { path: '/', redirect: '/admin', }, { path: '/login', name: 'login', meta: {title: '登录'}, component: () => import('./components/login.vue') }, { path: '/admin', name: 'admin', meta: {title: '主页'}, component: () => import('./components/admin.vue'), children: [ { path: 'operation', name: 'operation', meta: {title: '运营管理'}, component: () => import('./components/admin/operation.vue') }, { path: 'order', name: 'order', meta: {title: '订单中心'}, redirect: 'order/index', component: () => import('./components/admin/order.vue'), children: [ { path: 'index', name: 'index', meta: {title: ''}, component: () => import('./components/admin/ordercenter.vue') }, { path: 'detail', name: 'detail', meta: {title: '订单详情'}, component: () => import('./components/admin/orderdetail.vue') }, ] }, ] }, ] export default routes

这个是我部分的router路径配置表

 /*面包屑路径处理*/ eve_breadcrumbItem_change(){ var list = this.$route.fullPath.split('/')//list[0]:是空格 this.BreadcrumbItem = [] function fn(obj, arr, index,self) { if (obj.hasOwnProperty('children')&&obj['children'].length>0) { for (let one of obj.children) { if (one.name != 'index' && one.name == arr[index]) { self.BreadcrumbItem.push({'title': one.meta.title, 'path': list.slice(0,index+1).join('/')}) return one.hasOwnProperty('children')&&one['children'].length>0?fn(one,arr,index+1,self):false } } } } for(let one of this.$router.options.routes){ if(one.hasOwnProperty('name')&&one.name == list[1]){ this.BreadcrumbItem.push({'title': one.meta.title, 'path': one.path}) fn(one,list,2,this) } } } 

这个是就是本文的重点,其实也简单,就是递归了下路径名重新组装了下数据给面包屑传过去

 watch: { '$route'(to, from) { this.eve_breadcrumbItem_change() } }, ... mounted() { this.eve_breadcrumbItem_change() }, 

使本文来源[email protected]搞@^&代*@码)网9用也简单,无非watch检测下路径变化,避免刷新页面时没路径,在mounted里再调用一下。

结果

结果嘛,自然就解决问题。不过路径的配置可能会和大家的不同,我喜欢在分组下默认弄个index路径,我觉得这样结构比较好,这里大家注意下。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网

以上就是详解基于iview-ui的导航栏路径(面包屑)配置的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:详解基于iview-ui的导航栏路径(面包屑)配置

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址