使用el-tree完成下拉框单选功能
<label class="handle-label">部门:</label>
<el-select v-model="bm" ref="selectTree" class="wd150" placeholder="请选择" clearable @clear="handleTreeClear">
<el-option :value="bmId" :label="bm"
style="width: 450px;height: 200px;overflow: auto;background-color: #fff;">
<el-tree :data="bmlist" node-key="deptId" highlight-current
:props="{value: 'deptId',label: 'fullName', children: 'childTreeList',}"
@node-click="handleNodeClick"
:current-node-key="bm"
></el-tree>
</el-option>
</el-select>
export default {
data() {
return {
bm:"",//部门默认值
bmId:"",
bmlist:[],//部门列表
};
},
created() {
this.getBmList();
},
methods: {
//tree节点点击事件
handleNodeClick(node) {
this.bm = node.fullName;
this.bmId = node.deptId;
this.$refs.selectTree.blur();
this.search();
},
//部门select清空
handleTreeClear(){
// 将选择器的值置空
this.bm = '';
this.bmId = '';
this.search();
},
}
}