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:
|
<<: Docker deploys Laravel application to realize queue & task scheduling
>>: MySQL 5.7.21 Installer Installation Graphic Tutorial under Windows 10
Unlike other types of design, web design has been ...
This article shares the implementation code of jQ...
This article shares the specific code of js to im...
<br />Original text: http://jorux.com/archiv...
Data sorting asc, desc 1. Single field sorting or...
When using setinterval, it is found that it will ...
Copy code The code is as follows: <style> ....
This article shares the specific code of native j...
If there is an <input type="image">...
html <!DOCTYPE html> <html lang="en...
1. Embedded Software Level 1) Bootloader->Boot...
This article example shares the specific code of ...
Table of contents Preface 1.insert ignore into 2....
#String concatenation concat(s1,s2); concatenate ...
I took the bus to work a few days ago. Based on m...