el-tree单选

      <el-tree
        ref="tree"
        :data="treeData"
        @check-change="dataCheckChange"
        show-checkbox
        :props="defaultProps"
        :default-checked-keys="defaultcheckedkeys"
        :default-expanded-keys="defaultexpandedkeys"
        :check-strictly="true"
        node-key="id"
      ></el-tree>

过度数组list

dataCheckChange(data, checked, node) {
let indexs = this.list.indexOf(data.id)
if (indexs < 0 && this.list.length === 1 && checked) {
this. n o t i f y ( t i t l e : , m e s s a g e : , t y p e : s u c c e s s , d u r a t i o n : 2000 ) t h i s . notify({ title: &#x27;提示&#x27;, message: &#x27;只能选择一种预案场景&#x27;, type: &#x27;success&#x27;, duration: 2000 }) this. refs.tree.setChecked(data, false)
} else if (this.list.length === 0 && checked) {
// 发现数组为空, 且已选
// 防止数组有值 首先清空 ,在push
this.list = []
this.list.push(data.id)
} else if (indexs >= 0 && this.list.length === 1 && !checked) {
// 再次进行浮空操作
this.list = []
}
},

猜你喜欢

转载自blog.csdn.net/WmingCSDN/article/details/87893571