- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- Element樹(shù)形控件整合帶圖標的下拉菜單(tree+dropdo
本文主要講述:自定義樹(shù)形控件<el-tree>
Element UI 官網(wǎng)提供的樹(shù)形控件包含基礎的、可選擇的、自定義節點(diǎn)內容的、帶節點(diǎn)過(guò)濾的以及可拖拽節點(diǎn)的樹(shù)形結構 如下:
我想要的效果是支持搜索效果的樹(shù),將鼠標懸浮后顯示添加修改圖標,點(diǎn)擊圖標后彈出對應頁(yè)面;并且在每個(gè)文件夾前添加自定義圖標。
實(shí)現效果:
1、使用插槽(slot)
<el-col :span="4" :xs="24"> <!--目錄搜索功能--> <div class="head-container"> <el-input v-model="dirNameCn" placeholder="請輸入目錄名稱(chēng)" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" /> </div> <!--樹(shù)的展示--> <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" > <!--隱藏的新增等圖標--> <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、組件對應的JS
注意:樹(shù)的數據是從后端查詢(xún)回來(lái)的,保存在dirTreeOptions
里面
<script> export default { name: 'reqmdoctree', data() { return { // 左側搜索框內容 dirNameCn: '', // 目錄樹(shù)選項 dirTreeOptions: undefined, defaultProps: { children: "children", label: "label" }, // 樹(shù)形菜單中有無(wú)子節點(diǎn) yesChild: undefined, // 控制左側新增提示信息框 show: 0, // 查詢(xún)需求文檔信息參數 queryParams: { docNo: undefined, // 文檔編號 docNameEn: undefined, // 文檔英文名稱(chēng) dirNo: undefined,// 目錄編號 current: 1, // 當前頁(yè)數 size: 20 // 每頁(yè)顯示多少條 }, treeId: undefined, } }, methods: { /** 查詢(xún)需求目錄下拉樹(shù)結構 */ getTreeselect() { treeselect().then(response => { this.dirTreeOptions = response.data }) }, // 搜索值為過(guò)濾函數 filterNode(value, data) { if (!value) return true return data.label.indexOf(value) !== -1 }, // 節點(diǎn)被點(diǎn)擊時(shí)的回調函數 handleNodeClick(data) { // console.log(data) this.treeId = data.id this.yesChild = data.children this.queryParams.dirNo = data.id this.getList() }, // 樹(shù)中三個(gè)點(diǎn)的事件 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('是否確認刪除ID為' + this.uuid + '的數據項?', '警告', { confirmButtonText: '確定', cancelButtonText: '取消', type: 'warning' }).then(()=>{ return delObjTree(this.uuid) }).then(data => { this.getTreeselect() this.msgSuccess('刪除成功') }).catch(function() { }) }) } } }, // 左側新建目錄/文件 addDial(node, data) { // console.log(node, '---', data) this.reset() this.form.dirParentId = data.id this.open = true this.title = '添加需求文檔目錄配置表' }, // 左側鼠標懸浮展示圖標 mouseenter(data){ this.$set(data, 'show', true) }, // 左側鼠標離開(kāi)不展示圖標 mouseleave(data){ this.$set(data, 'show', false) }, //打開(kāi)新增資源彈窗 這里略...... } } </script>
說(shuō)明:
參考文檔:、
到此這篇關(guān)于Element樹(shù)形控件整合帶圖標的下拉菜單(tree+dropdown+input)的文章就介紹到這了,更多相關(guān)Element帶圖標的下拉菜單內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站