checkbox时控制最多只能选择4个
<template>
<el-tree
ref="groupTreeRef"
node-key="groupId"
show-checkbox
highlight-current
default-expand-all
check-strictly
:props="defaultProps"
:data="groupList"
@check="handleTreeCheck">
</el-tree>
</template>
<script>
export default {
methods: {
handleTreeCheck (currNode, checkedInfo) {
let groupId = currNode.groupId
let arr = checkedInfo.checkedKeys
let index = arr.findIndex(id => id === groupId)
if (arr.length > 10) {
this.showWarning('最多只能选择10个分组')
arr.splice(index, 1)
this.$refs.groupTreeRef.setCheckedKeys(arr)
}
},
}
}
</script>
5 回答1.4k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
2 回答886 阅读✓ 已解决
1 回答754 阅读✓ 已解决
1 回答726 阅读✓ 已解决
3 回答916 阅读
2 回答937 阅读
在check回调函数判断当前选中是否大于4,如果大于4个就把当前选中的删除掉

this.max 就是最多可选数