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

mysql workbench installation and configuration tutorial under centOS

This article shares the MySQL Workbench installat...

React Diff Principle In-depth Analysis

Table of contents Diffing Algorithm Layer-by-laye...

The difference between shtml and html

Shtml and asp are similar. In files named shtml, s...

Raspberry Pi msmtp and mutt installation and configuration tutorial

1. Install mutt sudo apt-get install mutt 2. Inst...

How to configure /var/log/messages in Ubuntu system log

1. Problem Description Today I need to check the ...

Coexistence of python2 and python3 under centos7 system

The first step is to check the version number and...

HTML implementation of a simple calculator with detailed ideas

Copy code The code is as follows: <!DOCTYPE ht...

Tips for turning pixels into comprehensive brand experiences

Editor: This article discusses the role that inte...

Simple implementation method of Linux process monitoring and automatic restart

Purpose: Under Linux, the server program may be d...

VUE Getting Started Learning Event Handling

Table of contents 1. Function Binding 2. With par...

JS asynchronous execution principle and callback details

1. JS asynchronous execution principle We know th...

Nginx 502 Bad Gateway Error Causes and Solutions

I have encountered the Nginx 502 Bad Gateway erro...