选择满5个后,其他选项禁用,需用户取消才能增加新的选择,利用optionprops的disabled属性管理。
代码如下:
<a-select v-model:value="model.field" showSearch mode="multiple" allowClear optionFilterProp="label">
<a-select-option v-for="(item, index) in sampleList" :key="index" :value="item.id"
:disabled="model.field !== undefined && model.field.length >= 5 && !model.field.includes(item.id)">
<span>{{ item.name}}</span>
</a-select-option>
</a-select>