el-cascader 级联选择器,限制多选个数

2,874 阅读1分钟

级联多选器,限制最多选择五个,多出的清除选中

在watch中监听数组变化

<el-cascader ref="cascader" v-model="form.taskType" :options="taskTypeOptions" clearable

:props="{checkStrictly:true,value:'taskCode',multiple: true}" class="small" collapse-tags>

watch: {

'form.taskType'() {

if (this.form.taskType.length > 5) {

this.$message({

type: 'warning',

message: '最多可选择五个',

showClose: true,

})

this.form.taskType.splice(-1, 1);

this.refs.cascader.refs.cascader.refs.panel.clearCheckedNodes();

}

},