The linkage method between menu and tab of vue+iview

The linkage method between menu and tab of vue+iview

Vue+iview menu and tab linkage

I am currently developing a backend management system using vue+iview. I hope to make a corresponding change to the tab and content on the right side of the left menu when I click on it.

But after working on the routing for a long time, I still haven't achieved this function.

When I first started using vue+iview, I didn’t know that iview-admin could be used directly, and the layout and other things were ready to use out of the box. However, I had already written my demo for a long time and couldn’t bear to give up.

1. Use iview's menu and tab for layout and place these two components on the main page

Since the data of menu and tab are the same and the styles need to be associated, vuex can be used for state management. The data and state variables that need to be managed are written in state, the operation actions are set in mutations, and some behaviors are listened in actions (my menu does not have expansion and contraction parts, so actions are not used)

2. After the layout is completed, click events should be added to the menu

on-select, first register the tab change event in mutations. When the left menu is clicked, check whether there is already a tab in the tab and set isExist=false. If it exists, isExist is changed to true. If not, add the menu relative index data to the array traversed by the tab.

mutationsType

In mutations:

The events in the menu component are:

First set the default route of the page in the tab component:

Then add the event:

iview+Vue multi-level menu linkage

I wrote a three-level menu linkage in the dumbest way possible.

<template>
  <div>
    <Select v-model="whereMap.model1"
            style="width:200px"
            @on-change="getSecond">
      <Option v-for="item in list1"
              :value="item.id"
              :key="item.id">{{ item.label }}</Option>
    </Select>
    <Select v-model="whereMap.model2"
            style="width:200px"
            @on-change="getThird">
      <Option v-for="item in list2"
              :value="item.id"
              :key="item.id">{{ item.label }}</Option>
    </Select>
    <Select v-model="whereMap.model3"
            style="width:200px">
      <Option v-for="item in list3"
              :value="item.id"
              :key="item.id">{{ item.label }}</Option>
    </Select>
    <Button class="search-btn"
            type="default"
            @click="searchClear">Clear</Button></div>
</template>
<script>
export default {
  data () {
    return {
      datatest: {
        l1: [
          {
            id: 'cat',
            label: 'cat'
          },
          {
            id: 'dog',
            label: 'dog'
          }
        ],
        l2: {
          cat: [{ id: 'sc', label: 'Kitten' }, { id: 'bc', label: 'Big cat' }],
          dog: [{ id: 'sd', label: 'Puppy' }, { id: 'bd', label: 'Big dog' }]
        },
        l3: {
          sc: [{ id: 'sc1', label: 'Little cat' }, { id: 'sc2', label: 'Little orange cat' }],
          bc: [{ id: 'bc1', label: 'Big tabby cat' }, { id: 'bc2', label: 'Big orange cat' }]
        }
      },
      list1: [],
      list2: [],
      list3: [],
      whereMap: {
        model1: '',
        model2: '',
        model3: ''
      }
    }
  },
  mounted () { this.init() },
  created () {
    this.init()
  },
  methods: {
    init () {
      this.list1 = this.datatest.l1
    },
    getSecond(val) {
      this.list2 = this.datatest.l2[val]
    },
    getThird (val) {
 
      this.list3 = this.datatest.l3[val]
    },
    searchClear () {
      console.log(this.whereMap)
      this.whereMap = {};
      this.list2 = [];
      this.list3 = [];
    }
  }
}
</script>

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue recursively implements three-level menu
  • Vue+element uses dynamic loading routing to implement the operation of displaying the three-level menu page
  • Vue.js realizes the three-level menu effect
  • Vue implements the background management permission system and the top bar three-level menu display function
  • How to change the secondary menu of Vue iview-admin framework to the third-level menu
  • Vue implements left and right menu linkage implementation code
  • Vue realizes three-level linkage of city selection based on mint-ui
  • Detailed explanation of Vue, element-ui, and axios to achieve three-level linkage between provinces, cities and districts
  • Example of how vue + elementUI can achieve three-level linkage between provinces, cities and counties
  • Vue implements three-level linkage dynamic menu

<<:  HeidiSQL tool to export and import MySQL data

>>:  Tutorial on downloading, installing and deploying Tomcat to IDEA (with two hot deployment setting methods for IDEA)

Recommend

Go to another file after submitting the form

<br />Question: How to write in HTML to jump...

How to run py files directly in linux

1. First create the file (cd to the directory whe...

HTML tutorial, understanding the optgroup element

Select the category selection. After testing, IE ...

Gogs+Jenkins+Docker automated deployment of .NetCore steps

Table of contents Environmental Description Docke...

Summary of Several Methods for Implementing Vertical Centering with CSS

In the front-end layout process, it is relatively...

MySQL 5.6.28 installation and configuration tutorial under Linux (Ubuntu)

mysql5.6.28 installation and configuration method...

Summary of several submission methods of HTML forms

The most common, most commonly used and most gener...

MySQL 8.0.11 Community Green Edition Installation Steps Diagram for Windows

In this tutorial, we use the latest MySQL communi...

Tutorial on resetting the root password of Mac MySQL

Disclaimer: This password reset method can direct...

1 minute Vue implements right-click menu

Table of contents Rendering Install Code Implemen...

Implementing form submission without refreshing the page based on HTML

Using ajax to implement form submission without re...

MySQL database optimization: index implementation principle and usage analysis

This article uses examples to illustrate the prin...

css add scroll to div and hide the scroll bar

CSS adds scrolling to div and hides the scroll ba...