首先來(lái)總結(jié)element ui 官方文檔的左側(cè)菜單結(jié)構(gòu),帶有el-submenu
為子級(jí)節(jié)點(diǎn),el-menu-item
表示沒(méi)有下級(jí)。當(dāng)然,菜單不能寫(xiě)死,因?yàn)椴藛我苍S不止兩級(jí),所以我們需要遞歸來(lái)實(shí)現(xiàn)。根據(jù)當(dāng)前節(jié)點(diǎn)是否有下級(jí)去判斷,如果有下級(jí),則繼續(xù)調(diào)用子級(jí),直到?jīng)]有下級(jí)為止,下面我貼上左側(cè)菜單所有的代碼:
成都創(chuàng)新互聯(lián)公司從2013年創(chuàng)立,先為霍林郭勒等服務(wù)建站,霍林郭勒等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為霍林郭勒企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
請(qǐng)求數(shù)據(jù)格式
[ { name: "首頁(yè)", id: -1, icon: "el-icon-picture-outline-round", url: "/index", children: [] }, { name: "按鈕", id: 20, icon: "el-icon-message-solid", url: "/button", children: [] }, { name: "測(cè)試1", id: 1, icon: "el-icon-s-claim", url: "", children: [ { id: 4, parentid: 1, name: "測(cè)試1-1", icon: "el-icon-chat-dot-round", url: "", children: [ { id: 8, parentid: 1, name: "測(cè)試1-1-1", icon: "el-icon-cloudy", url: "/test", children: [] }, { id: 9, parentid: 1, name: "測(cè)試1-1-2", icon: "el-icon-files", url: "/test1", children: [] } ] }, { id: 5, parentid: 1, name: "測(cè)試1-2", icon: "el-icon-shopping-cart-1", url: "/test3", children: [] } ] }, { name: "測(cè)試2", id: 2, icon: "el-icon-menu", url: "", children: [ { id: 6, parentid: 2, name: "測(cè)試2-1", icon: "el-icon-folder-checked", url: "", children: [] }, { id: 7, parentid: 2, name: "測(cè)試2-2", icon: "el-icon-folder-remove", url: "", children: [] } ] }, { name: "測(cè)試3", id: 3, icon: "el-icon-monitor", url: "", children: [] } ]
menu.vue
submenu.vue
這里有個(gè)知識(shí)點(diǎn)functional,不懂自行百度,文檔地址: https://cn.vuejs.org/v2/guide/render-function.html#search-query-sidebar
5{{props.data.name}} {{item.name}}
效果圖
總結(jié)
以上所述是小編給大家介紹的vue element 生成無(wú)線(xiàn)級(jí)左側(cè)菜單的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)會(huì)及時(shí)回復(fù)大家的!