首頁  >  文章  >  web前端  >  基於iview-ui的導覽列路徑配置(程式碼範例)

基於iview-ui的導覽列路徑配置(程式碼範例)

不言
不言轉載
2019-02-20 13:36:232469瀏覽

本篇文章帶給大家的內容是關於基於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': one.path})
                        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()
},

使用也簡單,無非watch偵測下路徑變化,避免刷新頁面時沒路徑,在mounted再呼叫一下。

結果

結果嘛,自然就解決問題。不過路徑的配置可能會跟大家的不同,我喜歡在分組下預設弄個index路徑,我覺得這樣結構比較好,這裡大家注意下。  

#

以上是基於iview-ui的導覽列路徑配置(程式碼範例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:segmentfault.com。如有侵權,請聯絡admin@php.cn刪除