您好,登錄后才能下訂單哦!
根據(jù)公司項(xiàng)目的需求,使用的是element-ui的nav-menu組件實(shí)現(xiàn)動態(tài)渲染左側(cè)導(dǎo)航條的功能,這里我只寫到了四級菜單。
代碼部分:
<el-menu class='el-menu-vertical-demo' :router='true' v-for='(item, index) in navMenu' :key='index'> <el-submenu v-if='item.childs' :index='item.name' :route = 'item.value' class='edit_wrapper' @mouseover.native="overShow" @mouseout.native="outHide"> <template slot='title'> <i :class='item.icon'></i> <span slot='title'>{{item.alias}}</span> <i class='iconfont icon-shenpi edit' v-show='haha'></i> </template> <el-submenu v-if='item1.childs' v-for= '(item1, index) in item.childs' :key='item1.name' :index='item1.name' :route='item1.value'> <template slot='title'> <i :class='item1.icon'></i> <span slot='title'>{{item1.alias}}</span> </template> <el-submenu v-for= '(item2, index) in item1.childs' :key='item2.name' v-if='item2.childs' :index='item2.name' :route = 'item2.value'> <template slot='title'> <i :class='item2.icon'></i> <span slot='title'>{{item2.alias}}</span> </template> <el-submenu v-for= '(item3, index) in item2.childs' :key='item3.name' v-if='item3.childs' ::index='item3.name' :route = 'item3.value'> <template slot='title'> <i :class='item3.icon'></i> <span slot='title'>{{item3.alias}}</span> </template> <el-menu-item v-for= '(item4, index) in item3.childs' :key='item3.name' v-if='item4.childs == null' :index='item4.name' :route = 'item4.value'> <span>{{item4.alias}}</span> </el-menu-item> </el-submenu> <el-menu-item v-for= '(item3, index) in item2.childs' :key='item3.name' v-if='item3.childs == null' :index='item3.name' :route = 'item3.value'> <span>{{item3.alias}}</span> </el-menu-item> </el-submenu> <el-menu-item v-for= '(item2, index) in item1.childs' :key='item2.name' v-if='item2.childs == null' :index='item2.name' :route = 'item2.value'> <span>{{item2.alias}}</span> </el-menu-item> </el-submenu> <el-menu-item v-for= '(item1, index) in item.childs' :key='item1.name' v-if='item1.childs == null' :index='item1.name' :route = 'item1.value'> <span>{{item1.alias}}</span> </el-menu-item> </el-submenu> <el-menu-item v-if='item.childs == null' :index='item.name' :route = 'item.value'> <i :class='item.icon'></i> <span slot='title'>{{item.alias}}</span> </el-menu-item> </el-menu>
數(shù)據(jù)部分:
navMenu: [{ name: 'serveList', icon: 'iconfont icon-shezhi', alias: '金融服務(wù)目錄', value: '', childs: [ { name: 'channelManage', icon: '', alias: '渠道管理', value: '', childs: [ { name: 'channelManage_in', icon: '', alias: '渠道內(nèi)部管理', value: '', childs: [ { name: 'financial', icon: '', alias: '金融類', value: '/serveManage/financial', }, { name: 'no_financial', icon: '', alias: '非金融類', value: '/serveManage/no_financial', }, { name: 'query_class', icon: '', alias: '查詢類', value: '/serveManage/query_class', }, { name: 'square_class', icon: '', alias: '沖正類', value: '/serveManage/square_class', }, ] }, { name: 'process_services', icon: '', alias: '流程服務(wù)', value: '/serveManage/process_services' }, { name: 'cooperation_services', icon: '', alias: '合作方服務(wù)', value: '/serveManage/cooperation_services' }, ] }, { name: 'saveManage', icon: '', alias: '風(fēng)險管理', value: '/serveManage/saveManage' }, { name: 'manageDecision', icon: '', alias: '管理決策', value: '/serveManage/manageDecision' }, { name: 'businessSupport', icon: '', alias: '業(yè)務(wù)支持', value: '/serveManage/businessSupport' }, { name: 'technicalSupport', icon: '', alias: '技術(shù)支持', value: '/serveManage/technicalSupport' } ] }, { name: 'serveRelation', icon: 'iconfont icon-shezhi', alias: '服務(wù)血緣關(guān)系', value: '/serveManage/serveRelation' }]
注意:因?yàn)楹衏hilds的目錄是沒有路由的,所以可以把它的value值設(shè)為空。
效果展示:
這樣我們就可以在其他頁面引入該組件就可以了。
以上這篇vue導(dǎo)航欄部分的動態(tài)渲染實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。