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

How to use JavaScript and CSS correctly in XHTML documents

In more and more websites, the use of XHTML is rep...

Four methods of using JS to determine data types

Table of contents Preface 1. typeof 2. instanceof...

js to implement a simple bullet screen system

This article shares the specific code of native j...

A brief analysis of MySQL parallel replication

01 The concept of parallel replication In the mas...

3 methods to restore table structure from frm file in mysql [recommended]

When mysql is running normally, it is not difficu...

Mini Program to Implement the Complete Shopping Cart

The mini program implements a complete shopping c...

How to install ELK in Docker and implement JSON format log analysis

What is ELK? ELK is a complete set of log collect...

Nginx Layer 4 Load Balancing Configuration Guide

1. Introduction to Layer 4 Load Balancing What is...

Summary of three rules for React state management

Table of contents Preface No.1 A focus No.2 Extra...

Hadoop 2.x vs 3.x 22-point comparison, Hadoop 3.x improvements over 2.x

Question Guide 1. How does Hadoop 3.x tolerate fa...

CSS menu button animation

To write a drop-down menu, click the button. The ...

How to realize vertical arrangement of text using CSS3

In a recent project, I wanted to align text verti...