element 中 el-menu 組件的無限極循環(huán)思路代碼詳解
實(shí)現(xiàn)思路主要組件嵌套(組件自己調(diào)用自己)
下面是組件所需要的數(shù)據(jù)
{ "code": 1, "data": { "menuVoList": [ { "childList": [ { "childList": [], "menu": { "createBy": "0-1", "createTime": 1587610158, "id": "2f006aed6a114579bd8b9809724428f7", "name": "系統(tǒng)用戶權(quán)限管理", "parentId": "6d68079a16b94292990f612237bd048e", "path": "/userallotrole", "updateBy": "0-1", "updateTime": 1587610221 } }, { "childList": [], "menu": { "createBy": "0-1", "createTime": 1587605059, "id": "c948265cdf27420eb7b6b502292c5990", "name": "系統(tǒng)用戶管理", "parentId": "6d68079a16b94292990f612237bd048e", "path": "/user", "updateBy": "0-1", "updateTime": 1587610230 } } ], "menu": { "createBy": "0-1", "createTime": 1587605025, "id": "6d68079a16b94292990f612237bd048e", "name": "用戶管理", "parentId": "", "path": "/#", "updateBy": "0-1", "updateTime": 1587610117 } }, { "childList": [ { "childList": [], "menu": { "createBy": "0-1", "createTime": 1587469457, "id": "d4b70897052742bb860cf14cea8cf131", "name": "新建/修改菜單", "parentId": "82e5ca1ab2e04d8faffeb973286771ec", "path": "/newMenu", "updateBy": "0-1", "updateTime": 1587469457 } } ], "menu": { "createBy": "0-1", "createTime": 1587469385, "id": "82e5ca1ab2e04d8faffeb973286771ec", "name": "菜單管理", "parentId": "", "path": "", "updateBy": "0-1", "updateTime": 1587469426 } }, { "childList": [ { "childList": [], "menu": { "createBy": "0-1", "createTime": 1587468494, "id": "3a092edd120d40b79322d8486e53e5a1", "name": "系統(tǒng)角色管理", "parentId": "ce5704f647d341fe8334ad12c6dd4a6b", "path": "/setrole", "updateBy": "0-1", "updateTime": 1587469340 } }, { "childList": [], "menu": { "createBy": "0-1", "createTime": 1587469360, "id": "61d0e4fecbed407d89b1ea5878072374", "name": "設(shè)置角色權(quán)限", "parentId": "ce5704f647d341fe8334ad12c6dd4a6b", "path": "/authorization", "updateBy": "0-1", "updateTime": 1587469360 } }, { "childList": [], "menu": { "createBy": "0-1", "createTime": 1587469520, "id": "a1a2f6bcbfba4a7f9178ef03ea0fe5b0", "name": "權(quán)限管理", "parentId": "ce5704f647d341fe8334ad12c6dd4a6b", "path": "/resource", "updateBy": "0-1", "updateTime": 1587624251 } } ], "menu": { "createBy": "0-1", "createTime": 1587468417, "id": "ce5704f647d341fe8334ad12c6dd4a6b", "name": "角色管理", "parentId": "", "path": "", "updateBy": "0-1", "updateTime": 1587468417 } } ] }, "message": "成功" }
現(xiàn)在我們來設(shè)置組件 (在 componet 文件夾里面建一個(gè) menu.vue) 代碼如下
<template> <div> <template v-for="value in menuData"> <el-submenu v-if="value.childList.length > '0'" :index="value.menu.name"> //判斷傳進(jìn)來的數(shù)據(jù)中 childList 數(shù)組length 是否大于零, 如果大于零表示 不是不需要在循環(huán)下去了 <template slot="title"> <i class="el-icon-s-tools" /> <span slot="title">{{ value.menu.name }}</span> </template> <MenuTree :menu-data="value.childList" /> </el-submenu> <el-menu-item v-else :index="value.menu.path"> <span slot="title">{{ value.menu.name }}</span> </el-menu-item> </template> </div> </template> <script> export default { name: 'MenuTree', props: ['menuData'] } </script> <style lang="scss" > .el-submenu__title i { color: #fff; } .el-menu--collapse { width: 54px; } </style>
接下來 在需要使用 menu 組件的地方引入剛才定義的組件
<template> <el-menu class="el-menu-vertical-demo" :collapse="isCollapse" background-color="#4A5A74" active-text-color="#ffd04b" text-color="#fff" :unique-opened="true" :default-active="this.$route.path" @select="handleSelect" > <menuTree :menu-data="list" /> </el-menu> </template> import menuTree from '@/component/menu' export default{ components: { menuTree }, data: { list: [] }, methods: { getMenuList({}).then(res => { //我這里是請(qǐng)求后臺(tái)得來得數(shù)據(jù),沒有數(shù)據(jù)直接用我上面得數(shù)據(jù),不過得像我下面這樣處理 if (res.status === 200) { this.list = res.data.data.menuVoList } }) } }
這樣,em-menu 組件的無限極循環(huán)便實(shí)現(xiàn)了,注意,我 上面代碼中 el-menu 的屬性可能多了一些,請(qǐng)根據(jù)自己需要?jiǎng)h除
到此這篇關(guān)于element 中 el-menu 組件的無限極循環(huán)的文章就介紹到這了,更多相關(guān)el-menu 組件無限極循環(huán)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
這應(yīng)該是最詳細(xì)的響應(yīng)式系統(tǒng)講解了
這篇文章主要介紹了這應(yīng)該是最詳細(xì)的響應(yīng)式系統(tǒng)講解了,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07常用的js驗(yàn)證和數(shù)據(jù)處理總結(jié)
遇到需要對(duì)數(shù)據(jù)及表單驗(yàn)證的,我相信大家都像我一樣,喜歡在網(wǎng)上找相關(guān)的方法,因?yàn)樽约簩懙脑挘潜容^耗時(shí)的。今天就給大家分享一下,自己在工作中總結(jié)的一些常用的js。2016-08-08js實(shí)時(shí)獲取并顯示當(dāng)前時(shí)間的方法
這篇文章主要介紹了js實(shí)時(shí)獲取并顯示當(dāng)前時(shí)間的方法,涉及javascript針對(duì)時(shí)間及頁面元素的相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07JS實(shí)現(xiàn)仿新浪黃色經(jīng)典滑動(dòng)門效果代碼
這篇文章主要介紹了JS實(shí)現(xiàn)仿新浪黃色經(jīng)典滑動(dòng)門效果代碼,是一款非常簡單的經(jīng)典鼠標(biāo)響應(yīng)滑動(dòng)切換效果,涉及JavaScript基于鼠標(biāo)事件動(dòng)態(tài)操作頁面元素的技巧,需要的朋友可以參考下2015-09-09D3.js實(shí)現(xiàn)力向?qū)D的繪制教程詳解
力向?qū)D是繪圖的一種算法,實(shí)現(xiàn)了用以模擬粒子物理運(yùn)動(dòng)的?velocity?Verlet?數(shù)值積分器。本文將利用D3.js實(shí)現(xiàn)力向?qū)D的繪制,需要的可以參考一下2022-11-11