您好,登錄后才能下訂單哦!
根據公司項目的需求,使用的是element-ui的nav-menu組件實現動態渲染左側導航條的功能,這里我只寫到了四級菜單。
代碼部分:
<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>
數據部分:
navMenu: [{ name: 'serveList', icon: 'iconfont icon-shezhi', alias: '金融服務目錄', value: '', childs: [ { name: 'channelManage', icon: '', alias: '渠道管理', value: '', childs: [ { name: 'channelManage_in', icon: '', alias: '渠道內部管理', 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: '流程服務', value: '/serveManage/process_services' }, { name: 'cooperation_services', icon: '', alias: '合作方服務', value: '/serveManage/cooperation_services' }, ] }, { name: 'saveManage', icon: '', alias: '風險管理', value: '/serveManage/saveManage' }, { name: 'manageDecision', icon: '', alias: '管理決策', value: '/serveManage/manageDecision' }, { name: 'businessSupport', icon: '', alias: '業務支持', value: '/serveManage/businessSupport' }, { name: 'technicalSupport', icon: '', alias: '技術支持', value: '/serveManage/technicalSupport' } ] }, { name: 'serveRelation', icon: 'iconfont icon-shezhi', alias: '服務血緣關系', value: '/serveManage/serveRelation' }]
注意:因為含有childs的目錄是沒有路由的,所以可以把它的value值設為空。
效果展示:
這樣我們就可以在其他頁面引入該組件就可以了。
以上這篇vue導航欄部分的動態渲染實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。