当前位置:网站首页>el-select和el-tree树形结构下拉单选和多选
el-select和el-tree树形结构下拉单选和多选
2022-07-19 00:52:00 【加蓓努力我先飞】
1.el-select和el-tree树形结构下拉单选
<template>
<div class="app-container caseManagementIndex scrollcontainer scrollcontainer_auto" ref="caseManagementIndex">
<el-select v-model="labelData" placeholder="请选择" :popper-append-to-body="false">
<el-option :value="selectTree" class="setstyle" disabled>
<el-tree :data="list" :props="defaultProps" ref="tree" :highlight-current="true" @node-click="handleNodeClick" default-expand-all></el-tree>
</el-option>
</el-select>
</div>
</template>
<script>
export default {
name: "caseManagementIndex",
// import引入的组件需要注入到对象中才能使用PopupTreeInput
components: {
},
props: [""],
data() {
// 这里存放数据
return {
labelData: "",
valueData:"",
selectTree: [],
defaultProps: {
children: 'children',
label: 'label'
},
list: [{
id: 1,
label: '一级 2',
children: [{
id: 3,
label: '二级 2-1',
children: [{
id: 4,
label: '三级 3-1-1'
}, {
id: 5,
label: '三级 3-1-2',
}]
}, {
id: 2,
label: '二级 2-2',
children: [{
id: 6,
label: '三级 3-2-1'
}, {
id: 7,
label: '三级 3-2-2',
}]
}]
}],
};
},
// 监听属性 类似于data概念
computed: {
},
// 监控data中的数据变化
watch: {
},
// 生命周期 - 创建完成(可以访问当前this实例)
created() {
},
// 生命周期 - 挂载完成(可以访问DOM元素)
mounted() {
console.log("flatten(fromData)", this.flatten(this.list));
},
// 方法集合
methods: {
flatten(arr) {
return [].concat(...arr.map(item => {
if (item.children) {
let arr = [].concat(item, ...this.flatten(item.children));
delete item.children;
return arr;
}
return [].concat(item);
}
));
},
handleNodeClick(data, self, child) {
console.log('data', data)
this.labelData = data.label;//展示部分
this.valueData = data.id;//传参---id
}
},
};
</script>
<style lang="scss">
.setstyle {
min-height: 200px;
padding: 0 !important;
margin: 0;
overflow: auto;
cursor: default !important;
}
</style>
<style lang="scss" scoped>
</style>
2.el-select和el-tree树形结构下拉多选
<template>
<div class="app-container caseManagementIndex scrollcontainer scrollcontainer_auto" ref="caseManagementIndex">
<el-select v-model="value" multiple placeholder="请选择" :popper-append-to-body="false">
<el-option :value="selectTree" class="setstyle" disabled>
<el-tree :data="list" :props="defaultProps" ref="tree" show-checkbox check-strictly :expand-on-click-node="false" check-on-click-node @check-change="checkChangeClick"></el-tree>
</el-option>
</el-select>
</div>
</template>
<script>
export default {
name: "caseManagementIndex",
// import引入的组件需要注入到对象中才能使用PopupTreeInput
components: {
},
props: [""],
data() {
// 这里存放数据
return {
value: [],
selectTree: [],
defaultProps: {
children: 'children',
label: 'label'
},
list: [{
id: 1,
label: '一级 2',
children: [{
id: 3,
label: '二级 2-1',
children: [{
id: 4,
label: '三级 3-1-1'
}, {
id: 5,
label: '三级 3-1-2',
}]
}, {
id: 2,
label: '二级 2-2',
children: [{
id: 6,
label: '三级 3-2-1'
}, {
id: 7,
label: '三级 3-2-2',
}]
}]
}],
};
},
// 监听属性 类似于data概念
computed: {
},
// 监控data中的数据变化
watch: {
},
// 生命周期 - 创建完成(可以访问当前this实例)
created() {
},
// 生命周期 - 挂载完成(可以访问DOM元素)
mounted() {
console.log("flatten(fromData)", this.flatten(this.list));
this.selectTree = this.flatten(this.list)
},
// 方法集合
methods: {
flatten(arr) {
return [].concat(...arr.map(item => {
if (item.children) {
let arr = [].concat(item, ...this.flatten(item.children));
delete item.children;
return arr;
}
return [].concat(item);
}
));
},
checkChangeClick(data, self, child) {
let datalist = this.$refs.tree.getCheckedNodes()
console.log('datalist', datalist)
this.value = []
datalist.forEach((item) => {
this.value.push(item.label)
})
let ids =datalist.map((item)=>{
return item.id})
console.log("ids",ids);//需要传递的idlist
}
},
};
</script>
<style lang="scss">
.setstyle {
min-height: 200px;
padding: 0 !important;
margin: 0;
overflow: auto;
cursor: default !important;
}
</style>
<style lang="scss" scoped>
</style>
边栏推荐
- INE Penetration Testing Basics 黑盒渗透测试过程
- Gateway injects applicationeventpublisher null pointer
- Leetcode- supplementary question 6 - sorting by hand
- Fast and slow in the real world
- &lt;/script&gt;&lt;script&gt;console.log(7890)-{&quot; xxx&quot; :&quot; aaa
- JVM knowledge map (under update)
- 【C 练习】公务员面试
- 大众消费的安全边际
- Deep understanding of ArrayList
- [Niuke brush questions] / * daily four programming questions to share*/
猜你喜欢
[Development Tutorial 4] crazy shell arm function mobile phone - development interface connection tutorial
View的measure测量过程梳理
金融银行软件测试超大型攻略,最受欢迎的金融银行大揭 秘附面试题
高数 | 【多元函数微分学】概念篇 —— 连续、可偏导及可微之间的关系
[translation] introduce OPTA. Terrain on rails
19.3 - > 19.12 patching is interrupted. How to continue?
The LAAS protocol elephant of defi 2.0 is the key to revitalizing the development of defi track
Raspberry pie 3B replaces 4.9.80 kernel (64bit)
ReplicaSet
Based on yarn1 Sharing of monorepo practice of X
随机推荐
Is it safe for Guangzhou GF Securities to open an account? How much is the handling charge
[Niuke brush questions] / * daily four programming questions to share*/
INE Penetration Testing Basics 黑盒渗透测试过程
Based on yarn1 Sharing of monorepo practice of X
7. [WebGIS practice] special topic - API key
金融银行软件测试超大型攻略,最受欢迎的金融银行大揭 秘附面试题
Conditions and details of polar coordinate substitution for solving the limit of multivariate functions with high numbers
Arthas查看已加载类的源码(jad)
Award winning research | what does the perfect ar development platform look like to make virtual reality?
My creation anniversary
五行八卦的学问
启牛送的银河证券账户安全吗?
MySQL修改密碼報錯 ERROR 1064 (42000):
7.18 simulation summary
arguments.callee的用法
Award winning research | what does the perfect ar development platform look like to make virtual reality?
Go语言 变量与数据类型
【翻译】介绍一下Opta。Rails上的Terraform
【文件操作的重难点详解】
OGC WebGIS 常用服务标准(WMS/WMTS/TMS/WFS)速查