This article example shares the specific code of Vue+Element UI to implement the drop-down menu encapsulation for your reference. The specific content is as follows 1. RenderingI'll post a rendering first. The menu items are not styled, and there is no border shown in the picture (the border is the border of the outer container). You can modify the styles of the others as needed. 2. Component packagingThe component encapsulation uses CSS animation, positioning, and the drop-down menu component el-dropdown provided by Element UI. The code is as follows <template> <div class="all" @click="clickFire"> <span class="item-border"> <el-image class="item" style="width: 24px; height: 24px" fit="cover" :lazy="isLazy" :src="itemProperty.url" :title="itemProperty.name" :placeholder="itemProperty.name" ></el-image> </span> <div class="wrap-item"></div> <!-- Drop-down menu --> <el-dropdown class="dropMenu" @command="handleCommand"> <span class="el-dropdown-link" v-text="itemProperty.name"></span> <el-dropdown-menu slot="dropdown" class="dropMenuitems"> <!-- <el-dropdown-item>Golden Cake</el-dropdown-item> <el-dropdown-item>Lion head</el-dropdown-item> <el-dropdown-item>Snail Rice Noodles</el-dropdown-item> --> <el-dropdown-item class="dropMenu-item" v-for="(item, index) in itemProperty.menus" :key="index" :command="item" >{{ item }}</el-dropdown-item > </el-dropdown-menu> </el-dropdown> </div> </template> <script> export default { props: { itemProperty: Object, require: true, }, data() { return { isLazy: true, item: name: 'item', url: require('../../../static/imgs/menus/warning.png'), menus: [ 'submenu-1', 'submenu-2', 'submenu-3', 'submenu-4', 'submenu-5', ], }, } }, mounted() { this.$data.item = this.$props.itemProperty // console.log(this.$props.itemProperty) }, methods: { //Parent icon click event clickFire() { //Parameter 1: custom component event, which can be called in the parent component to trigger the value transfer of parent-child components; Parameter 2: data passed to the parent component [can be in array form] this.$emit('clickItem', this.$data.item) }, //Drop-down menu click event handleCommand(command) { // console.log(command) this.$emit('handleCommand', command) }, }, } </script> <style lang="less" scoped> .all { // border: 1px solid skyblue; display: inline-block; position: relative; width: 65px; height: 65px; // overflow: hidden; } // Innermost layer.item-border { display: inline-block; margin: 0 auto; margin-left: 0px; margin-top: 10px; width: 44px; height: 44px; border-radius: 50%; border: 3px solid skyblue; // background-color: slateblue; .item { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } } // Outermost layer.wrap-item { position: absolute; top: 0; left: 0; display: inline-block; width: 56px; height: 56px; border: 5px dotted transparent; border-left: 5px dotted #73ffff; border-left-width: 3px; border-right-color: #73ffff; border-top-color: transparent; border-radius: 50%; // background-color: burlywood; animation: circle 3s infinite linear; } @keyframes circle { 0% { transform: rotate(0deg); } 100% { transform: rotate(-360deg); } } //Drop-down menu.dropMenu { margin-top: 5px; // background-color: yellowgreen; color: #fff; //Title item.el-dropdown-link { cursor: pointer; } //Menu sub-item.el-dropdown-menu__item { color: red !important; } .dropMenu-item { background-color: rosybrown; } } </style> 3. Example of use in parent component<template> <!-- Functional module: Use subcomponents-pay attention to the custom events clickItem and handleCommand --> <div class="funcModules"> <RingItem class="ringitem-style" v-for="(item, index) in funcItems" :key="index" :itemProperty="item" @clickItem="clickRingItem" @handleCommand="handleCommandDropMenu" /> </div> </template> <script> //1-Import subcomponentimport RingItem from '../Controls/RingItem' export default { components: //2-Register component RingItem, }, data() { return { //Function module icon resources funcItems: [ { name: 'System Management', url: require('../../../static/imgs/menus/management.png'), menus: ['Details Management', 'About Us'], }, ], } }, methods: { /** * RingItem subcomponent click event: value is the value passed by emit in the subcomponent*/ clickRingItem(value) { //Judge the name attribute value of the subcomponent and implement the corresponding business logic switch (value.name) { case 'system management': { console.log('system management') //Execute page jump-Management Center (depending on your needs, add business logic) //this.$router.push({ path: '/admincenter' }) break } } }, /** * RingItem subcomponent: drop-down menu click event (value is the value passed by emit in the subcomponent) */ handleCommandDropMenu(value) { console.log(value) switch (value.name) { case 'Details Management': { console.log('system management') //Execute page jump-Management Center (depending on your needs, add business logic) //this.$router.push({ path: '/admincenter' }) break } case 'About us': { console.log('system management') //Execute page jump-Management Center (depending on your needs, add business logic) //this.$router.push({ path: '/admincenter' }) break } } }, }, } </script> <style lang="less" scoped> //Style adjustment</style> 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:
|
<<: Steps for Django to connect to local MySQL database (pycharm)
Preface Recently, I encountered such a problem wh...
CSS3Please Take a look at this website yourself, ...
Table of contents Create a vue + ts project using...
MTR stands for Mini-Transaction. As the name sugg...
Example: tip: This component is based on vue-crop...
Here we take the Jenkins container as an example ...
Computed properties Sometimes we put too much log...
In the process of database operation, it is inevi...
In some scenarios, we need to modify our varchar ...
1. Optimization of commonly used HTML tags HTML s...
jQuery realizes the effect of theater seat select...
1 CSS style without semicolon ";" 2 Tags...
1. Environment: CentOS7, Openssl1.1.1k. 2. Concep...
HTML is a hybrid language used for publishing on ...
It is recommended that you do not set the width, h...