Vue+Elementui el-tree樹只能選擇子節(jié)點(diǎn)并且支持檢索功能
效果:
只能選擇子節(jié)點(diǎn) 添加配置
添加檢索代碼
源碼:
<template> <div> <el-button size="small" type="primary" clearable :disabled="disabled" @click="showSign"> 危險(xiǎn)點(diǎn)評(píng)估 </el-button> <!-- 規(guī)則綁定流程節(jié)點(diǎn)--> <el-dialog title="危險(xiǎn)點(diǎn)評(píng)估" :visible.sync="show" v-if="show" width="700px" append-to-body> <el-form ref="formEvaluate" :model="formEvaluate" label-width="80px"> <el-form-item label="危險(xiǎn)點(diǎn)"> <el-input placeholder="輸入關(guān)鍵字進(jìn)行檢索" clearable v-model="filterText"> </el-input> <el-tree ref="Tree" :data="treeData" :show-checkbox="true" :check-strictly="true" node-key="id" default-expand-all :highlight-current="true" :expand-on-click-node="false" @node-click="nodeClick" :props="defaultProps" :check-on-click-node="true" @check="handleCheck" :filter-node-method="filterNode" > <span class="custom-tree-node" slot-scope="{ node, data }"> <span> <span class="custom-expand-icon" v-if="!data.children || data.children.length === 0"> <img src="@/assets/images/fl.png" class="icon" /> </span> <span class="custom-expand-icon" v-else> <img src="@/assets/images/home.png" class="icon" /> </span> {{ data.treeName }} </span> </span> </el-tree> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="show = false">取 消</el-button> <el-button type="primary" @click="saveGz">確 定</el-button> </div> </el-dialog> </div> </template> <script> import Treeselect from '@riophae/vue-treeselect'; import '@riophae/vue-treeselect/dist/vue-treeselect.css'; import { deptTreeSelect } from "@/api/system/user"; import { selectPcModelByTableZb } from '@/api/index-analysis/indicator-maintenance' import { doubleTicketAppraise } from '@/api/flowable/definition' export default { name: 'tsSelectTree', components: { Treeselect }, props: { value: { default:'' }, conf: { type: Object }, disabled: {} }, data() { return { currentValue: undefined, filterText: '', options: [], list: [], loading: false, show:false, cache: [], input_val: this.value, object:this.conf, formEvaluate:{ formName:null, formId:null, nodeId:null, nodeName:null, lcName:null, lcId:null, tableZbbmId:null, tableZbbmIds:[], }, //規(guī)則數(shù)據(jù) treeData:[], //選中的數(shù)據(jù)json數(shù)組 jsonData:[], evaluateArr:[], defaultProps: { children: "children", label: "label", disabled: function (data, node) {//帶子級(jí)的節(jié)點(diǎn)不能選中 if (data.children && data.children.length > 0) { return true } else { return false } } }, } }, watch: { value: { handler(val) { if (val !== this.currentValue) { if (this.multiple) { if (Object.prototype.toString.call(val) === '[object String]') { try { this.currentValue = JSON.parse(val) } catch (e) { this.currentValue = val.split(',') } } if (Object.prototype.toString.call(val) === '[object Array]') { this.currentValue = val } } else { this.currentValue = val || undefined } } }, immediate: true, deep: true }, currentValue() { this.$emit('input', this.currentValue) this.$emit('change', this.currentValue) }, filterText(val) { this.$refs.Tree.filter(val); } }, created() { this.getDate() const object = this.object this.getTreeList() }, methods: { filterNode(value, data) { if (!value) return true; return data.treeName.indexOf(value) !== -1; }, handleCheck(data,node){ this.evaluateArr = node.checkedNodes }, // 點(diǎn)擊樹節(jié)點(diǎn) 多選邏輯todo nodeClick(data,node, indeterminate) { if(node.childNodes.length > 0){ return } }, cancel(){ this.show = false }, showSign() { this.show = true; }, // 節(jié)點(diǎn)單擊事件 handleNodeClick(data) { this.currentValue = data.label; sessionStorage.setItem('deptId',data.id) this.show = false }, remoteMethod(query) { if (query !== '') { this.loading = true setTimeout(() => { this.getDate(query) }, 500) } else { this.options = this.cache } }, getDate(query) { deptTreeSelect().then((response) => { // 獲取樹形的部門數(shù)據(jù) this.options = response.data; sessionStorage.setItem('deptInfo',this.options && JSON.stringify(this.options)) }); }, getTreeList() { const params = { tableZb:'WXDPG' }; selectPcModelByTableZb(params).then((response) => { this.treeData = response.data; }); }, saveGz(){ this.formEvaluate.tableZbbmId = '' this.formEvaluate.tableZbbmIds = [] const arr = this.evaluateArr if(this.evaluateArr.length ==0){ this.$message.warning('請(qǐng)選擇一條危險(xiǎn)點(diǎn)') return } }, } } </script>
到此這篇關(guān)于Vue+Elementui el-tree樹只能選擇子節(jié)點(diǎn)并且支持檢索的文章就介紹到這了,更多相關(guān)Vue Elementui el-tree樹選擇子節(jié)點(diǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue項(xiàng)目中常用的工具函數(shù)總結(jié)
這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中常用的工具函數(shù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-09-09Vue CLI3移動(dòng)端適配(px2rem或postcss-plugin-px2rem)
這篇文章主要介紹了Vue CLI3移動(dòng)端適配(px2rem或postcss-plugin-px2rem),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04VUE使用draggable實(shí)現(xiàn)組件拖拽
這篇文章主要為大家詳細(xì)介紹了VUE使用draggable實(shí)現(xiàn)組件拖拽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04使用vue.js在頁(yè)面內(nèi)組件監(jiān)聽scroll事件的方法
今天小編就為大家分享一篇使用vue.js在頁(yè)面內(nèi)組件監(jiān)聽scroll事件的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09vue el-tree 默認(rèn)展開第一個(gè)節(jié)點(diǎn)的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue el-tree 默認(rèn)展開第一個(gè)節(jié)點(diǎn)的實(shí)現(xiàn)代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05一次vue項(xiàng)目?jī)?yōu)化的實(shí)際操作記錄
用vue開發(fā)項(xiàng)目上線以后,發(fā)現(xiàn)首頁(yè)加載速度非常慢,如果項(xiàng)目比較大,甚至可能出現(xiàn)10s以上的等待,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目?jī)?yōu)化的相關(guān)資料,需要的朋友可以參考下2022-09-09封裝 axios+promise通用請(qǐng)求函數(shù)操作
這篇文章主要介紹了封裝 axios+promise通用請(qǐng)求函數(shù)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08