Element組件庫動態(tài)生成導(dǎo)航

圖片來源網(wǎng)絡(luò)

Element-ui和Vue Router不知道的自行谷歌哈

先來看下怎么樣動態(tài)加載nav導(dǎo)航

html代碼
      <el-menu :default-active="$router.path" router class="el-menu-demo" mode="horizontal" @select="handleSelect" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
        <label v-for="(item,index) in navData" :key="index">
          <el-menu-item :index=item.url>
            <i :class=item.icon></i>
            <span slot="title">{{item.name}}</span>
          </el-menu-item>
        </label>
      </el-menu>
js模擬從后臺獲取的導(dǎo)航數(shù)據(jù)
      navData: [
            {
                name: "ECharts",
                url: "/Echarts",
                icon: "el-icon-menu"
            },
            {
                name: "菜單選項2",
                url: "2",
                icon: "el-icon-tickets"
            },
            {
                name: "菜單選項3",
                url: "3",
                icon: "el-icon-message"
            },
            {
                name: "菜單選項4",
                url: "4",
                icon: "el-icon-phone-outline"
            },
            {
                name: "菜單選項5",
                url: "5",
                icon: "el-icon-star-off"
            },
            {
                name: "菜單選項6",
                url: "6",
                icon: "el-icon-setting"
            }
        ]

實現(xiàn)效果

截圖

復(fù)雜導(dǎo)航生成(包含二級菜單和三級菜單)

html代碼
<el-menu class="el-menu-vertical-demo" @select="handleOpen" :collapse="isCollapse">
  <label v-for="(item,index) in listNav" :key="index">
    <label v-for="(itemR,indexR) in item.extopts" :key="indexR">
      <label v-for="(iconitem2,iconIndex2) in (indexR).match(/(\S*)@@/)" :key="iconIndex2">
        <label v-if="iconIndex2 > 0">
          <el-menu-item :url="item.url" :index=iconitem2 v-if="item.items.length == 0">
            <label v-for="(iconitem1,iconIndex1) in (indexR).match(/@@(\S*)/)" :key="iconIndex1">
              <label v-if="iconIndex1 > 0">
                <i :class=iconitem1></i>
              </label>
            </label>
            <span slot="title">{{ item.text}}{{iconitem2}}</span>
          </el-menu-item>
          <el-submenu :index=iconitem2 v-else>
            <template slot="title">
              <label v-for="(iconitem3,iconIndex3) in (indexR).match(/@@(\S*)/)" :key="iconIndex3">
                <label v-if="iconIndex3 > 0">
                  <i :class=iconitem3></i>
                </label>
              </label>
              <span slot="title" v-show="false">{{ item.text}}{{iconitem2}}111</span>
            </template>
            <label v-for="(item1,index1) in item.items" :key="index1">
              <label v-for="(itemR1,indexR1) in item1.extopts" :key="indexR1">
                <el-menu-item :url="item1.url" :index=indexR1 v-if="item1.items.length == 0">{{item1.text}}{{indexR1}}</el-menu-item>
                <el-submenu :index=indexR1 v-else>
                  <template slot="title">{{item1.text}}{{indexR1}}</template>
                  <label v-for="(item2,index2) in item1.items" :key="index2">
                    <label v-for="(itemR2,indexR2) in item2.extopts" :key="indexR2">
                      <el-menu-item :url="item2.url" :index=indexR2>{{item2.text}}{{indexR2}}</el-menu-item>
                    </label>
                  </label>
                </el-submenu>
              </label>
            </label>
          </el-submenu>
        </label>
      </label>
    </label>
  </label>
</el-menu>
js模擬從后臺獲取的導(dǎo)航數(shù)據(jù)
        listNav: [
            {
                name: "dldt",
                text: "地理地圖",
                url: "http://10.156.121.38:9000/gwUap",
                extopts: { "/dldt@@el-icon-location": "" },
                items: [],
                outter: false
            },
            {
                name: "jccx",
                text: "基礎(chǔ)查詢",
                url: "http://10.156.121.38:9000/gwUap",
                extopts: { "/jccx@@el-icon-search": "" },
                items: [
                    {
                        name: "cxdw",
                        text: "查詢定位",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/cxdw": "" },
                        items: [
                            {
                                name: "dwcx",
                                text: "定位查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/dwcx": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "dlzhcx",
                                text: "電纜綜合查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/dlzhcx": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "scfzsszhcx",
                                text: "生產(chǎn)輔助設(shè)施綜合查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/scfzsszhcx": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "tdzhcx",
                                text: "通道綜合查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/tdzhcx": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "tdnxcx",
                                text: "通道年限查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/tdnxcx": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "jhcx",
                                text: "幾何查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/jhcx": "" },
                                items: [],
                                outter: false
                            }
                        ],
                        outter: false
                    },
                    {
                        name: "dlzycxfx",
                        text: "電纜資源查詢分析",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/dlzycxfx": "" },
                        items: [
                            {
                                name: "dlmspmcx",
                                text: "電纜埋設(shè)剖面查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/dlmspmcx": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "dljpmtcx",
                                text: "電纜井剖面圖查詢",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/dljpmtcx": "" },
                                items: [],
                                outter: false
                            }
                        ],
                        outter: false
                    },
                    {
                        name: "txsc",
                        text: "圖形輸出",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/txsc": "" },
                        items: [
                            {
                                name: "dqtfdy",
                                text: "當(dāng)前圖幅打印",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/dqtfdy": "" },
                                items: [],
                                outter: false
                            },
                            {
                                name: "lkdy",
                                text: "拉框打印",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: { "/lkdy": "" },
                                items: [],
                                outter: false
                            }
                        ],
                        outter: false
                    }
                ],
                outter: false
            },
            {
                name: "ywgl",
                text: "業(yè)務(wù)管理",
                url: "http://10.156.121.38:9000/gwUap",
                extopts: { "/ywgl@@el-icon-tickets": "" },
                items: [
                    {
                        name: "zzbd",
                        text: "政治保電",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/zzbd": "" },
                        items: [
                            {
                                name: "bdrwd",
                                text: "保電任務(wù)單",
                                url: "http://10.156.121.38:9000/gwUap",
                                extopts: {
                                    "/BusinessManagement/politicalProtection/protectTacks/protectTack":
                                        ""
                                },
                                items: [],
                                outter: false
                            }
                        ],
                        outter: false
                    },
                    {
                        name: "gzt",
                        text: "工作臺",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/gzt": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "dmgl",
                        text: "斷面管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/dmgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "jhgl",
                        text: "計劃管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/jhgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "xsjcgl",
                        text: "巡視檢測管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/xsjcgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "yhgl",
                        text: "隱患管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/yhgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "fxgk",
                        text: "風(fēng)險管控",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/fxgk": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "qxgl",
                        text: "缺陷管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/qxgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "gzgl",
                        text: "故障管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/gzgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "yxztpj",
                        text: "運行狀態(tài)評價",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/yxztpj": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "gcjsgl",
                        text: "工程建設(shè)管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/gcjsgl": "" },
                        items: [],
                        outter: false
                    }
                ],
                outter: false
            },
            {
                name: "jkzz",
                text: "監(jiān)控主站",
                url: "http://10.156.121.38:9000/gwUap/Monitoring",
                extopts: { "/jkzz@@el-icon-view": "" },
                items: [],
                outter: false
            },
            {
                name: "znxj",
                text: "智能巡檢",
                url: "http://10.156.121.38:9000/gwUap",
                extopts: { "/Polling@@el-icon-sort": "" },
                items: [],
                outter: false
            },
            {
                name: "tjfx",
                text: "統(tǒng)計分析",
                url: "http://10.156.121.38:9000/gwUap/Statistics",
                extopts: { "/tjfx@@el-icon-edit": "" },
                items: [],
                outter: false
            },
            {
                name: "zhxx",
                text: "綜合信息",
                url: "http://10.156.121.38:9000/gwUap/Synthesize",
                extopts: { "/zhxx@@el-icon-document": "" },
                items: [],
                outter: false
            },
            {
                name: "zbkb",
                text: "指標看板",
                url: "http://10.156.121.38:9000/gwUap/Board",
                extopts: { "/zbkb@@el-icon-news": "" },
                items: [],
                outter: false
            },
            {
                name: "ztt",
                text: "專題圖",
                url: "http://10.156.121.38:9000/gwUap",
                extopts: { "/ztt@@el-icon-picture-outline": "" },
                items: [
                    {
                        name: "jkfb",
                        text: "監(jiān)控分布",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/jkfb": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "jkgj",
                        text: "監(jiān)控警告",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/jkgj": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "tdzyl",
                        text: "通道占用率",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/tdzyl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "tdfj",
                        text: "通道分級",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/tdfj": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "gcjsgl",
                        text: "工程建設(shè)管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/gcjsgl": "" },
                        items: [],
                        outter: false
                    },
                    {
                        name: "yhgl",
                        text: "隱患管理",
                        url: "http://10.156.121.38:9000/gwUap",
                        extopts: { "/yhgl": "" },
                        items: [],
                        outter: false
                    }
                ],

實現(xiàn)效果

截圖
截圖

這個動態(tài)生成的復(fù)雜導(dǎo)航因為有些測試需要做涛救,所以菜單名字就一直沒有改忆植,不影響實現(xiàn)效果

沒看明白或者是有更好方法的小伙伴們可以私信我

這里卿洋
愿喜??

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末榆俺,一起剝皮案震驚了整個濱河市历葛,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌当纱,老刑警劉巖央星,帶你破解...
    沈念sama閱讀 212,718評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異惫东,居然都是意外死亡,警方通過查閱死者的電腦和手機毙石,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,683評論 3 385
  • 文/潘曉璐 我一進店門廉沮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人徐矩,你說我怎么就攤上這事滞时。” “怎么了滤灯?”我有些...
    開封第一講書人閱讀 158,207評論 0 348
  • 文/不壞的土叔 我叫張陵坪稽,是天一觀的道長。 經(jīng)常有香客問我鳞骤,道長窒百,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,755評論 1 284
  • 正文 為了忘掉前任豫尽,我火速辦了婚禮篙梢,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘美旧。我一直安慰自己渤滞,他們只是感情好贬墩,可當(dāng)我...
    茶點故事閱讀 65,862評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著妄呕,像睡著了一般陶舞。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上绪励,一...
    開封第一講書人閱讀 50,050評論 1 291
  • 那天肿孵,我揣著相機與錄音,去河邊找鬼优炬。 笑死颁井,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的蠢护。 我是一名探鬼主播雅宾,決...
    沈念sama閱讀 39,136評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼葵硕!你這毒婦竟也來了眉抬?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,882評論 0 268
  • 序言:老撾萬榮一對情侶失蹤懈凹,失蹤者是張志新(化名)和其女友劉穎蜀变,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體介评,經(jīng)...
    沈念sama閱讀 44,330評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡库北,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,651評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了们陆。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片寒瓦。...
    茶點故事閱讀 38,789評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖坪仇,靈堂內(nèi)的尸體忽然破棺而出杂腰,到底是詐尸還是另有隱情,我是刑警寧澤椅文,帶...
    沈念sama閱讀 34,477評論 4 333
  • 正文 年R本政府宣布喂很,位于F島的核電站,受9級特大地震影響皆刺,放射性物質(zhì)發(fā)生泄漏少辣。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 40,135評論 3 317
  • 文/蒙蒙 一芹橡、第九天 我趴在偏房一處隱蔽的房頂上張望毒坛。 院中可真熱鬧,春花似錦、人聲如沸煎殷。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,864評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽豪直。三九已至劣摇,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間弓乙,已是汗流浹背末融。 一陣腳步聲響...
    開封第一講書人閱讀 32,099評論 1 267
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留暇韧,地道東北人勾习。 一個月前我還...
    沈念sama閱讀 46,598評論 2 362
  • 正文 我出身青樓,卻偏偏與公主長得像懈玻,于是被迫代替她去往敵國和親巧婶。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,697評論 2 351

推薦閱讀更多精彩內(nèi)容

  • 1涂乌、通過CocoaPods安裝項目名稱項目信息 AFNetworking網(wǎng)絡(luò)請求組件 FMDB本地數(shù)據(jù)庫組件 SD...
    陽明先生_X自主閱讀 15,969評論 3 119
  • 五六公里的路程艺栈,每天花一小時走完。堅持了幾天之后湾盒,會很容易從當(dāng)初的掙扎心里接受成為一種必不可少的正常行為湿右。路走得多...
    相國618閱讀 211評論 0 0
  • 一旦我們發(fā)現(xiàn)自己想要學(xué)習(xí)點新技能、想要提高個人能力時罚勾,就會發(fā)現(xiàn)原來的無聊再也沒有了毅人,取而代之的則是,總覺得找不到時...
    楊刀刀daoker閱讀 1,612評論 3 2
  • 天尖殃、漸漸的暗了下來堰塌。 遠處天地相接之處; 烏云壓頂分衫、 空氣變的格外的凝固; 氣流逐漸從地面上升般此, 仿佛傳說中的天在...
    松木葉子閱讀 896評論 0 0