1、有时需求需要下拉多选,但是显示选中个数, 如最多可以选中四个,其它项置灰不可选
2、核心代码:(termActive.findIndex(i=> i === item.labelCode) === -1)
<div class="select-item" v-if="state.tabList.length">
<span>监测项:</span>
<a-select
v-model:value="termActive"
style="width: 250px"
@change="termChange"
mode="multiple"
:maxTagCount="1"
>
<a-select-option :value="item.labelCode" v-for="item in state.tabList" :disabled="termActive.length == 4 && (termActive.findIndex(i=> i === item.labelCode) === -1)" :key="item.labelCode">{{ item.labelName }}</a-select-option>
</a-select>
</div>
<script setup>
let termActive = ref([]);
</script>
4、最终效果:
慢半拍,给彼此更多的空间!