element tree单选
<el-tree :data="depData" show-checkbox node-key="id" ref="treedep" default-expand-all @check-change = "change2" :check-strictly="true" :props="defaultProps"> </el-tree>
selectOrg: {
orgsid: []
}
change2(data,checked,msg3){
const indexs = this.selectOrg.orgsid.indexOf(data.id)
if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) {
console.log('only one')
this.$message({
message: '只能选择一个部门!',
type: 'error',
showClose: true
})
this.$refs.treedep.setChecked(data, false)
} else if (this.selectOrg.orgsid.length === 0 && checked) {
this.selectOrg.orgsid = []
this.selectOrg.orgsid.push(data.id)
} else if (
indexs >= 0 &&
this.selectOrg.orgsid.length === 1 &&
!checked
) {
this.selectOrg.orgsid = []
}
},