写一个vue 和 element-ui 点击el-select下拉框出发el-tree勾选的代码
时间: 2023-10-30 19:05:21 浏览: 85
<template>
<div>
<el-select v-model="selected" @change="handleChange">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-tree :data="data" :props="defaultProps" ref="tree" />
</div>
</template>
<script>
export default {
data() {
return {
selected: '',
options: [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' },
],
data: [
{
label: 'Level 1',
children: [
{ label: 'Level 1-1' },
{ label: 'Level 1-2' },
{ label: 'Level 1-3' },
],
},
{
label: 'Level 2',
children: [
{ label: 'Level 2-1' },
{ label: 'Level 2-2' },
{ label: 'Level 2-3' },
],
},
],
defaultProps: {
children: 'children',
label: 'label',
checked: 'checked',
isLeaf: 'isLeaf',
},
}
},
methods: {
handleChange() {
this.$nextTick(() => {
const tree = this.$refs.tree
const node = tree.getNode(this.selected)
if (node) {
tree.setChecked(node.data, true)
}
})
},
},
}
</script>
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)