想实现功能:如果有子节点,父节点就不能选中,但是现在不管点击SAP,费控,都能选中到框里。
我之前尝试了disabled和其他方法,不管用,不想在选项前面加一个CheckBox,直接双击选中就OK。
烦请指导,感谢!
```html
<div id="app" >
<el-select
v-model="saveForm.upResId"
clearable
placeholder="请选择"
@clear="handleClear"
ref="selectUpResId">
<el-option hidden key="upResId" :value="saveForm.upResId" :label="upResName" >
</el-option>
<el-input
placeholder="输入关键字进行过滤"
v-model="filterText"
>
</el-input>
<el-tree icon-class="el-icon-remove-outline"
:node-key="id"
class="filter-tree"
:data="data"
:props="defaultProps"
:expand-on-click-node="false"
:highlight-current="true"
:check-on-click-node="true"
@node-click="handleNodeClick"
:filter-node-method="filterNode"
ref="tree"
>
</el-tree>
</el-select>
</div>
var vm= new Vue({
el: '#app',
watch: {
filterText:function(val) {
this.$refs.tree.filter(val);
}
},
methods: {
filterNode:function(value, data) {
if (!value) return true;
return data.lable.indexOf(value) !== -1;
},
// 节点点击事件
handleNodeClick:function (data,checked, node) {
// 这里主要配置树形组件点击节点后,设置选择器的值;自己配置的数据,仅供参考
this.upResName = data.lable
this.saveForm.upResId = data.id
// // 选择器执行完成后,使其失去焦点隐藏下拉框的效果
this.$refs.selectUpResId.blur()
},
// 选择器配置可以清空选项,用户点击清空按钮时触发
handleClear:function () {
// 将选择器的值置空
this.upResName = ''
this.saveForm.upResId = ''
}
}
})