Vue recursively implements three-level menu

Vue recursively implements three-level menu

This article example shares the specific code of Vue recursively implementing the three-level menu for your reference. The specific content is as follows

Parent Component

<template>
    <div class="menu-level-menu menu-level-menu-enter" v-if="showLevelMenu">
      <menu-item class="menu-item" :menuDate="menuList"></menu-item>
    </div>
</template>

Subcomponents

<template>
  <div>
    <div class="" v-for="(menu, index) in menuDate" :key="index">
    // Each menu item <div class="menu-row" @click="menuSpread(menu)"
           :class="[{'menu-row-selected': menu.selected && menu.children.length <= 0}]">
        <div class="menu-row-left">
          <div class="menu-row-left-line" :class="[{'menu-selected': menu.selected && menu.children.length <= 0}]"></div>
          <i class="iconfont" :class="[menu.menuIcon, {'color-icon': showIconColor(menu)}]"></i>
        </div>
        <div class="menu-row-right">
          <span :class="[{'font-16': menu.level === '0'}]">{{menu.menuName}}</span>
          <i class="c" v-if="menu.children.length <= 0"></i>
          <i class="iconfont icon-liebiaoxiala" v-if="menu.children.length>0 && !menu.selected"></i>
          <i class="iconfont icon-liebiaoshouqi" v-if="menu.children.length>0 && menu.selected"></i>
        </div>
      </div>
      // Recursively display the menu <menu-item v-show="menu.selected" v-if="menu.children.length>0" :menuDate="menu.children"></menu-item>
    </div>
  </div>
</template>
<script>
  export default {
    props: {
      menuDate: Array
    },
    name: 'MenuItem',
    methods: {
      menuSpread (menu) {
        if (menu.menuRouter) this.$router.push(menu.menuRouter);
        menu.selected = !menu.selected;
        this.recursion(this.menuDate, menu);
      },
      recursion (all, temp) {
        all.forEach(item => {
          if (item.menuName !== temp.menuName) {
            item.selected = false;
            this.recursion(item.children, temp);
          }
        });
      },
      showIconColor (menu) {
        let show = false;
        if (menu.level === '0') {
          menu.children.forEach(item => {
            if (item.children.length <= 0 && item.selected) {
              show = true;
            }
            if (item.children.length > 0) {
              item.children.forEach(item => {
                if (item.selected) {
                  show = true;
                }
              });
            }
          });
        }
        return show;
      }
    }
  };
</script>

Rendering

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • 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
  • The linkage method between menu and tab of vue+iview
  • 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

<<:  Docker deploys Laravel application to realize queue & task scheduling

>>:  MySQL 5.7.21 Installer Installation Graphic Tutorial under Windows 10

Recommend

A brief discussion on the design of Tomcat multi-layer container

Table of contents Container Hierarchy The process...

Vue custom bullet box effect (confirmation box, prompt box)

This article example shares the specific code of ...

Vue uses vue-quill-editor rich text editor and uploads pictures to the server

Table of contents 1. Preparation 2. Define the gl...

Perfect solution for JavaScript front-end timeout asynchronous operation

Table of contents What happens if a piece of code...

Detailed explanation of the pitfalls of mixing MySQL order by and limit

In MySQL, we often use order by for sorting and l...

Implementation of docker-compose deployment of zk+kafka+storm cluster

Cluster Deployment Overview 172.22.12.20 172.22.1...

MySQL 8.0.19 installation detailed tutorial (windows 64 bit)

Table of contents Initialize MySQL Install MySQL ...

Source code reveals why Vue2 this can directly obtain data and methods

Table of contents 1. Example: this can directly g...

mysql charset=utf8 do you really understand what it means

1. Let's look at a table creation statement f...

Some thoughts and experience sharing on web page (website) design and production

First, before posting! Thanks again to I Want to S...

MySQL Router implements MySQL read-write separation

Table of contents 1. Introduction 2. Configure My...

JavaScript implements simple date effects

The specific code of JavaScript date effects is f...

Mysql Chinese sorting rules description

When using MySQL, we often sort and query a field...

Detailed explanation of several methods of deduplication in Javascript array

Table of contents Array deduplication 1 Double-la...