This article mainly describes: Custom tree control Requirements:The tree controls provided by the Element UI official website include basic, selectable, custom node content, node filtering, and draggable node tree structures as follows: The effect I want is a tree that supports search effects. When the mouse is hovered, the add and modify icons will be displayed. When the icon is clicked, the corresponding page will pop up; and a custom icon will be added in front of each folder. Result: Implementation steps:1. Use slots <el-col :span="4" :xs="24"> <!--Directory search function--> <div class="head-container"> <el-input v-model="dirNameCn" placeholder="Please enter the directory name" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" /> </div> <!--Tree display--> <div class="head-container"> <el-tree :data="dirTreeOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" default-expand-all @node-click="handleNodeClick" icon-class="el-icon-folder-opened" node-key="id" :check-on-click-node="true" > <!--Hidden new icons--> <span class="custom-tree-node" slot-scope="{ node, data }" @mouseenter="mouseenter(data)" @mouseleave="mouseleave(data)"> <span>{{ node.label }}</span> <div> <i v-show="data.show" class="el-icon-circle-plus" style="color: #00afff" @click="addDial(node, data)"/> <!--Hidden drop-down selection--> <el-dropdown trigger="click" placement="right" @command="(command) => {handleCommand(command)}"> <i v-show="data.show" class="el-icon-more" style="color: #D3D3D3"/> <el-dropdown-menu slot="dropdown"> <el-dropdown-item command="a">Rename</el-dropdown-item> <el-dropdown-item command="b">Delete</el-dropdown-item> </el-dropdown-menu> </el-dropdown> </div> </span> </el-tree> </div> </el-col> 2. JS corresponding to the component Note: The tree data is queried from the backend and saved in <script> export default { name: 'reqmdoctree', data() { return { // The content of the left search box dirNameCn: '', // Directory tree options dirTreeOptions: undefined, defaultProps: { children: "children", label: "label" }, //Whether there is a child node in the tree menu yesChild: undefined, // Control the newly added prompt information box on the left show: 0, // Query requirement document information parameters queryParams: { docNo: undefined, // Document number docNameEn: undefined, // Document English name dirNo: undefined, // Directory number current: 1, // Current page size: 20 // How many items are displayed per page }, treeId: undefined, } }, methods: { /** Query the drop-down tree structure of the required directory*/ getTreeselect() { treeselect().then(response => { this.dirTreeOptions = response.data }) }, // Search value is filter function filterNode(value, data) { if (!value) return true return data.label.indexOf(value) !== -1 }, // callback function when the node is clicked handleNodeClick(data) { // console.log(data) this.treeId = data.id this.yesChild = data.children this.queryParams.dirNo = data.id this.getList() }, //Events of three points in the tree handleCommand(command) { if (command == 'a') { selectReqNo(this.treeId).then(response => { this.uuid = response.msg getObjTree(response.msg).then(response => { this.form = response.data this.open = true this.title = 'Modify the requirements document directory configuration table' }) }) } if (command == 'b') { if (this.yesChild != undefined) { this.$notify.error({ title: 'Warning', message: 'There are other folders in this directory' }) } else { selectReqNo(this.treeId).then(response => { this.uuid = response.msg this.$confirm('Are you sure you want to delete the data item with ID ' + this.uuid + '?', 'Warning', { confirmButtonText: 'Confirm', cancelButtonText: 'Cancel', type: 'warning' }).then(()=>{ return delObjTree(this.uuid) }).then(data => { this.getTreeselect() this.msgSuccess('Deleted successfully') }).catch(function() { }) }) } } }, // Create a new directory/file on the left addDial(node, data) { // console.log(node, '---', data) this.reset() this.form.dirParentId = data.id this.open = true this.title = 'Add requirement document directory configuration table' }, // Display icon when mouse hovers on the left mouseenter(data){ this.$set(data, 'show', true) }, // The icon will not be displayed when the left mouse leaves mouseleave(data){ this.$set(data, 'show', false) }, //Open the new resource pop-up window here...... } } </script> illustrate: Reference documents: element UI, tree control integrated drop-down selection This is the end of this article about Element tree control integrating drop-down menu with icons (tree+dropdown+input). For more content related to Element drop-down menu with icons, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL index leftmost principle example code
>>: Detailed explanation of Linux environment variable configuration strategy
background When working on the blockchain log mod...
Most of this article refers to other tutorials on...
When we are writing projects, we often encounter ...
This article shares with you how to install Kylin...
Text shadow text-shadow property effects: 1. Lowe...
Today I will share with you a neon button animati...
Table of contents (1) Introduction: (2) The ways ...
Table of contents 1. innodb_buffer_pool_size 2. i...
Docker Quickly Install Zookeeper I haven't us...
After the worker process is started, it will firs...
1. I searched for a long time on the Internet but...
Table of contents 1. Structure string 2. Return t...
While working on a Linux server, assigning static...
Links to the current page. ------------------- Com...
1. Download the 64-bit zip file from the official...