Element樹形控件整合帶圖標(biāo)的下拉菜單(tree+dropdown+input)
本文主要講述:自定義樹形控件<el-tree>
需求說明:
Element UI 官網(wǎng)提供的樹形控件包含基礎(chǔ)的、可選擇的、自定義節(jié)點內(nèi)容的、帶節(jié)點過濾的以及可拖拽節(jié)點的樹形結(jié)構(gòu) 如下:
我想要的效果是支持搜索效果的樹,將鼠標(biāo)懸浮后顯示添加修改圖標(biāo),點擊圖標(biāo)后彈出對應(yīng)頁面;并且在每個文件夾前添加自定義圖標(biāo)。
實現(xiàn)效果:
實現(xiàn)步驟:
1、使用插槽(slot)
<el-col :span="4" :xs="24"> <!--目錄搜索功能--> <div class="head-container"> <el-input v-model="dirNameCn" placeholder="請輸入目錄名稱" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" /> </div> <!--樹的展示--> <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" > <!--隱藏的新增等圖標(biāo)--> <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)"/> <!--隱藏的下拉選--> <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">重命名</el-dropdown-item> <el-dropdown-item command="b">刪除</el-dropdown-item> </el-dropdown-menu> </el-dropdown> </div> </span> </el-tree> </div> </el-col>
2、組件對應(yīng)的JS
注意:樹的數(shù)據(jù)是從后端查詢回來的,保存在dirTreeOptions
里面
<script> export default { name: 'reqmdoctree', data() { return { // 左側(cè)搜索框內(nèi)容 dirNameCn: '', // 目錄樹選項 dirTreeOptions: undefined, defaultProps: { children: "children", label: "label" }, // 樹形菜單中有無子節(jié)點 yesChild: undefined, // 控制左側(cè)新增提示信息框 show: 0, // 查詢需求文檔信息參數(shù) queryParams: { docNo: undefined, // 文檔編號 docNameEn: undefined, // 文檔英文名稱 dirNo: undefined,// 目錄編號 current: 1, // 當(dāng)前頁數(shù) size: 20 // 每頁顯示多少條 }, treeId: undefined, } }, methods: { /** 查詢需求目錄下拉樹結(jié)構(gòu) */ getTreeselect() { treeselect().then(response => { this.dirTreeOptions = response.data }) }, // 搜索值為過濾函數(shù) filterNode(value, data) { if (!value) return true return data.label.indexOf(value) !== -1 }, // 節(jié)點被點擊時的回調(diào)函數(shù) handleNodeClick(data) { // console.log(data) this.treeId = data.id this.yesChild = data.children this.queryParams.dirNo = data.id this.getList() }, // 樹中三個點的事件 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 = '修改需求文檔目錄配置表' }) }) } if (command == 'b') { if (this.yesChild != undefined) { this.$notify.error({ title: '警告', message: '此目錄下還有別的文件夾' }) } else { selectReqNo(this.treeId).then(response => { this.uuid = response.msg this.$confirm('是否確認(rèn)刪除ID為' + this.uuid + '的數(shù)據(jù)項?', '警告', { confirmButtonText: '確定', cancelButtonText: '取消', type: 'warning' }).then(()=>{ return delObjTree(this.uuid) }).then(data => { this.getTreeselect() this.msgSuccess('刪除成功') }).catch(function() { }) }) } } }, // 左側(cè)新建目錄/文件 addDial(node, data) { // console.log(node, '---', data) this.reset() this.form.dirParentId = data.id this.open = true this.title = '添加需求文檔目錄配置表' }, // 左側(cè)鼠標(biāo)懸浮展示圖標(biāo) mouseenter(data){ this.$set(data, 'show', true) }, // 左側(cè)鼠標(biāo)離開不展示圖標(biāo) mouseleave(data){ this.$set(data, 'show', false) }, //打開新增資源彈窗 這里略...... } } </script>
說明:
參考文檔:element UI、樹形控件整合下拉選
到此這篇關(guān)于Element樹形控件整合帶圖標(biāo)的下拉菜單(tree+dropdown+input)的文章就介紹到這了,更多相關(guān)Element帶圖標(biāo)的下拉菜單內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue.js引用背景圖background無效的3種解決方案
這篇文章主要介紹了vue.js引用背景圖background無效的3種解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08vue element table中自定義一些input的驗證操作
這篇文章主要介紹了vue element table中自定義一些input的驗證操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07vue+ElementPlus框架Container 布局容器不能鋪滿整個屏幕的解決方案
這篇文章主要介紹了vue+ElementPlus框架Container 布局容器不能鋪滿整個屏幕的解決方案,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01ant desing vue table 實現(xiàn)可伸縮列的完整例子
最近在使用ant-design-vue做表格時,遇到要做一個可伸縮列表格的需求,在網(wǎng)上一直沒有找到好的方法,于是小編動手自己寫個可以此功能,下面小編把ant desing vue table 可伸縮列的實現(xiàn)代碼分享到腳本之家平臺供大家參考2021-05-05使用Vant完成DatetimePicker 日期的選擇器操作
這篇文章主要介紹了使用Vant完成DatetimePicker 日期的選擇器操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11