Vue实现侧边导航栏于Tab页关联的示例代码
程序员文章站
2022-03-09 18:16:14
目录技术栈效果分析技术栈 侧边栏用 antdtab使用element效果
&...
技术栈
- 侧边栏用
- antdtab使用element
效果
<template> <div class="main-card"> <el-row> <el-col :span="3"> <div class="menu-all"> <div class="menu-head"> <span class="menu-head-title">仓库管理</span>/<span class="menu-head-title" @click="goback" >大屏</span > </div> <!-- <div class="menu-body"> <div class="menu-item" @click="opentabs(item)" v-for="item in menuitems" :key="item"> <i class="el-icon-s-home" v-if="item.value === '01'"></i>{{ item.name }} </div> </div> --> <a-menu mode="inline" theme="dark" :openkeys="openkeys" v-model="selectedkeys" @openchange="onopenchange" > <a-sub-menu v-for="item in menuitems" :key="item.value"> <span slot="title" ><a-icon type="appstore" /><span>{{ item.name }}</span></span > <a-menu-item v-for="childrenitem in item.children" :key="childrenitem.value" @click="addtabs(childrenitem)" >{{ childrenitem.name }} </a-menu-item> </a-sub-menu> </a-menu> </div> </el-col> <el-col :span="21"> <el-row> <el-col :span="24"> <div> <el-tabs v-model="editabletabsvalue" type="card" closable @tab-remove="removetab"> <el-tab-pane v-for="item in editabletabs" :key="item.name" :label="item.title" :name="item.name"> <component :is="item.content"></component> </el-tab-pane> </el-tabs> </div> </el-col> </el-row> </el-col> </el-row> </div> </template> <script> export default { data(){ return{ openkeys: [],//控制一级菜单折叠展开的数组 存放一级菜单的value selectedkeys: '',//控制二级菜单高亮 存放二级菜单value //侧边导航菜单数组 menuitems: [ { name: '应入应出报表', value: '0', children: [ { name: '应入库单量报表', value: '01', content: () => import('@/views/main/index/qtyreportindex.vue'), }, { name: '应入库台数报表', value: '02', content: () => import('@/views/main/index/qtyreportindexqty.vue'), }, { name: '应出库单量报表', value: '03', content: () => import('@/views/main/index/handoverreportindex.vue'), }, { name: '应出库台数报表', value: '04', content: () => import('@/views/main/index/handoverreportindexqty.vue'), }, ], }, { name: '预测', value: '1', children: [ { name: '到货登记', value: '11', content: () => import('@/views/main/index/asnhdrdockindex.vue'), }, { name: '仓库利用率', value: '12', content: () => import('@/views/main/index/whuteindex.vue'), }, { name: '库内库存', value: '13', content: () => import('@/views/main/index/imodsstorageindex.vue'), }, ], }, { name: '指标', value: '2', children: [ { name: '单仓提货率', value: '201', content: () => import('@/views/main/index/singlewhdeliveryscaleindex.vue'), }, { name: '中转在库时长', value: '202', content: () => import('@/views/main/index/transitdurationinwhindex.vue'), }, { name: '重复sn', value: '203', content: () => import('@/views/main/index/dwexceptionbarcodeindex.vue'), }, { name: '盘点日清单', value: '204', content: () => import('@/views/main/index/inventoryrqindex.vue'), }, { name: '移库指标监控', value: '205', content: () => import('@/views/main/index/transferindexindex.vue'), }, { name: '拣货库位分析汇总报表', value: '206', content: () => import('@/views/main/index/pickingbylocsumindex.vue'), }, { name: '装车报表汇总', value: '207', content: () => import('@/views/main/index/loadingsummaryindex.vue'), }, { name: '出库sn报错率', value: '208', content: () => import('@/views/main/index/dwbarcodeerrorrptindex.vue'), }, { name: '拣货库位分析明细', value: '209', content: () => import('@/views/main/index/dwpickfxmxindex.vue'), }, { name: '不按批次拣货库区维度', value: '210', content: () => import('@/views/main/index/notpickingbybatchindex.vue'), }, ], }, ], editabletabsvalue: '',//tab页当前active的item editabletabs: [],//tab页数组 } }, methods:{ // 用于其他页面跳转来到主页并打开tab页的方法 // gotable(item) { // this.openkeys = [item.value.substring(0, 1)] // this.selectedkeys = item.value // this.$store.commit('updatehomeorindexswitch', false) // this.opentabs(item) //}, addtab(item) { let onoff = false; this.editabletabs.foreach((x) => { if (x.name == item.name) { this.editabletabsvalue = item.name onoff=true return; } }) if(!onoff){ this.editabletabs.push({ title: item.name, name: item.name, content: item.content, }) this.editabletabsvalue = item.name } }, //关闭tab页触发 targetname = item.name removetab(targetname) { let tabs = this.editabletabs let activename = this.editabletabsvalue if (activename === targetname) { tabs.foreach((tab, index) => { if (tab.name === targetname) { let nexttab = tabs[index + 1] || tabs[index - 1] if (nexttab) { activename = nexttab.name } else { this.openkeys = [] this.selectedkeys = '' } } }) } this.editabletabsvalue = activename this.editabletabs = tabs.filter((tab) => tab.name !== targetname) }, }, watch:{ editabletabsvalue(val) { this.menuitems.foreach((menuitem) => { if (menuitem.children) { menuitem.children.foreach((childrenitem) => { if (childrenitem.name === val) { this.openkeys = [childrenitem.value.substring(0, 1)] this.selectedkeys = childrenitem.value return } }) } }) }, } } </script>
分析
这一套组件不能单凭element一个单一框架实现,侧边导航栏我们需要控制折叠,控制高亮,以及菜单组三个参数,而element的导航菜单控制折叠展开菜单组的参数是一个函数@open控制,所以我们没有办法通过代码去控制某个菜单组的展开收起所以跨框架做了这么一个功能 记录一下
到此这篇关于vue实现侧边导航栏于tab页关联的示例代码的文章就介绍到这了,更多相关vue 侧边导航栏于tab页关联内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!