Vue implements the sample code of associating the side navigation bar with the Tab page

Vue implements the sample code of associating the side navigation bar with the Tab page

Technology Stack

  • For sidebar
  • Antdtab uses element

Effect

Please add a description of the image

<template>
	  <div class="main-card">
          <el-row>
            <el-col :span="3">
              <div class="menu-all">
                <div class="menu-head">
                  <span class="menu-head-title">Warehouse Management</span>/<span class="menu-head-title" @click="goBack"
                    >Large screen</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: [], //Control the folding and unfolding of the first-level menu to store the value of the first-level menu
      SelectedKeys: '', //Control the secondary menu to highlight and store the secondary menu value
      //Side navigation menu array menuItems: [
        {
          name: 'Incoming and outgoing reports',
          value: '0',
          children: [
            {
              name: 'Report on the quantity of orders to be received',
              value: '01',
              content: () => import('@/views/main/index/qtyReportIndex.vue'),
            },
            {
              name: 'Report on the number of units to be put into storage',
              value: '02',
              content: () => import('@/views/main/index/qtyReportIndexQty.vue'),
            },
            {
              name: 'Report on the quantity of orders to be shipped',
              value: '03',
              content: () => import('@/views/main/index/handoverReportIndex.vue'),
            },
            {
              name: 'Report on the number of units to be shipped out',
              value: '04',
              content: () => import('@/views/main/index/handoverReportIndexQty.vue'),
            },
          ],
        },
        {
          name: 'Prediction',
          value: '1',
          children: [
            {
              name: 'Arrival Registration',
              value: '11',
              content: () => import('@/views/main/index/asnHdrDockIndex.vue'),
            },
            {
              name: 'Warehouse Utilization',
              value: '12',
              content: () => import('@/views/main/index/whUteIndex.vue'),
            },
            {
              name: 'Inventory in the warehouse',
              value: '13',
              content: () => import('@/views/main/index/imOdsStorageIndex.vue'),
            },
          ],
        },
        {
          name: 'Indicator',
          value: '2',
          children: [
            {
              name: 'Single warehouse pick-up rate',
              value: '201',
              content: () => import('@/views/main/index/singleWhDeliveryScaleIndex.vue'),
            },
            {
              name: 'Transit time in warehouse',
              value: '202',
              content: () => import('@/views/main/index/transitDurationInWhIndex.vue'),
            },
            {
              name: 'Repeat SN',
              value: '203',
              content: () => import('@/views/main/index/dwExceptionBarcodeIndex.vue'),
            },
            {
              name: 'Daily Inventory List',
              value: '204',
              content: () => import('@/views/main/index/inventoryRqIndex.vue'),
            },
            {
              name: 'Database transfer indicator monitoring',
              value: '205',
              content: () => import('@/views/main/index/transferIndexIndex.vue'),
            },
            {
              name: 'Picking location analysis summary report',
              value: '206',
              content: () => import('@/views/main/index/pickingByLocSumIndex.vue'),
            },
            {
              name: 'Loading report summary',
              value: '207',
              content: () => import('@/views/main/index/loadingSummaryIndex.vue'),
            },
            {
              name: 'Outbound SN error rate',
              value: '208',
              content: () => import('@/views/main/index/dwBarcodeErrorRptIndex.vue'),
            },
            {
              name: 'Picking location analysis details',
              value: '209',
              content: () => import('@/views/main/index/dwPickFxmxIndex.vue'),
            },
            {
              name: 'Storage area dimension not based on batch picking',
              value: '210',
              content: () => import('@/views/main/index/notPickingByBatchIndex.vue'),
            },
          ],
        },
      ],
      editableTabsValue: '', //The currently active item on the tab page
      editableTabs: [], //tab page array }
		},
		methods:{
	// Method used to jump from other pages to the home page and open the tab page // 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
      }
    },
    //Close the tab page to trigger 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>

analyze

This set of components cannot be implemented by a single framework of element. For the side navigation bar, we need to control the folding, highlighting, and menu group parameters. The parameter of the element's navigation menu to control the folding and expanding menu group is a function @open control, so we have no way to control the expansion and collapse of a menu group through code, so we made such a function across the framework to record it.

insert image description here

This concludes this article about the sample code for Vue's implementation of the side navigation bar and the Tab page association. For more relevant content about Vue's side navigation bar and the Tab page association, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue implements tab navigation bar and supports left and right sliding function
  • vue elementUI uses tabs to link with the navigation bar
  • Vue custom bottom navigation bar Tabbar implementation code
  • Write a mobile inertial sliding & rebound Vue navigation bar component ly-tab

<<:  Detailed explanation of the spacing problem between img tags

>>:  43 Web Design Mistakes Web Designers Should Watch Out For

Recommend

A brief discussion on order reconstruction: MySQL sharding

Table of contents 1. Objectives 2. Environmental ...

Universal solution for MySQL failure to start under Windows system

MySQL startup error Before installing MySQL on Wi...

Dynamically edit data in Layui table row

Table of contents Preface Style Function Descript...

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and insta...

Compile CPP files using G++ in Ubuntu

When I used g++ to compile the cpp file for the f...

Analysis of Linux configuration to achieve key-free login process

1.ssh command In Linux, you can log in to another...

JavaScript implementation of verification code case

This article shares the specific code for JavaScr...

RGBA alpha transparency conversion calculation table

Conversion between rgba and filter values ​​under...

Use and analysis of Mysql Explain command

The mysql explain command is used to show how MyS...

JS realizes picture digital clock

This article example shares the specific code of ...

XHTML 2.0 New Features Preview

<br />Before browsers can handle the next ge...

In-depth understanding of the role of Vuex

Table of contents Overview How to share data betw...