Vue+Elementui el-tree樹只能選擇子節(jié)點并且支持檢索功能
更新時間:2024年12月03日 10:50:03 作者:沉默是金~
這篇文章給大家介紹了Vue+Element UI el-tree樹只能選擇子節(jié)點并且支持檢索的文章,通過實例代碼給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
效果:
只能選擇子節(jié)點 添加配置
添加檢索代碼
源碼:
<template> <div> <el-button size="small" type="primary" clearable :disabled="disabled" @click="showSign"> 危險點評估 </el-button> <!-- 規(guī)則綁定流程節(jié)點--> <el-dialog title="危險點評估" :visible.sync="show" v-if="show" width="700px" append-to-body> <el-form ref="formEvaluate" :model="formEvaluate" label-width="80px"> <el-form-item label="危險點"> <el-input placeholder="輸入關(guā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) {//帶子級的節(jié)點不能選中 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 }, // 點擊樹節(jié)點 多選邏輯todo nodeClick(data,node, indeterminate) { if(node.childNodes.length > 0){ return } }, cancel(){ this.show = false }, showSign() { this.show = true; }, // 節(jié)點單擊事件 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('請選擇一條危險點') return } }, } } </script>
到此這篇關(guān)于Vue+Elementui el-tree樹只能選擇子節(jié)點并且支持檢索的文章就介紹到這了,更多相關(guān)Vue Elementui el-tree樹選擇子節(jié)點內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue CLI3移動端適配(px2rem或postcss-plugin-px2rem)
這篇文章主要介紹了Vue CLI3移動端適配(px2rem或postcss-plugin-px2rem),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧2020-04-04使用vue.js在頁面內(nèi)組件監(jiān)聽scroll事件的方法
今天小編就為大家分享一篇使用vue.js在頁面內(nèi)組件監(jiān)聽scroll事件的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09vue el-tree 默認展開第一個節(jié)點的實現(xiàn)代碼
這篇文章主要介紹了vue el-tree 默認展開第一個節(jié)點的實現(xiàn)代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05