<template>
<div>
<span>2.select下拉列表用tree代替,双击选中</span>
<el-select
ref="elSelect"
v-model="msg"
>
//不用option下拉列表,用empty下拉列表
//老版插槽写法
<template #empty>
<el-tree
:data="data"
@node-click="handleNodeClick"
@dblclick.native="handleNodeClick" />
</template>
</el-select>
</div>
</template>
<script>
export default {
name: 'TextComponent',
data() {
return {
data: [{ label: '1组', value: 1, children: [{ label: '人物1', value: 'dyn' }, { label: '人物2', value: 'yqc' }] }],
selectTree: {}
}
},
methods: {
handleNodeClick(obj) {
if (!obj.label) {
this.msg = this.selectTree.label
this.$refs.elSelect.blur()
} else {
this.selectTree = Object.assign({}, obj)
}
}
}
}
</script>