最近工作中遇到客户需要在单选的下拉框中对所选项进行标识:
组件在设置为多选时,是可以对选中项进行标识,但是单选没有这个功能,如下:
a-select 加入mode为tags 和 multiple 模式下可用,那如何实现单选也能设置呢?
分析可以将a-select-option的显示文本和赋值到文本框的文本区分开来,就可以设置成功了,如下:
<a-select option-label-prop="label" :value="value">
<a-select-option v-for="item in types" :key="item.key" :value="item.id" :label="item.name">
<a-icon type="check" v-if="item.id===value"/>
{{item.name}}
</a-select-option>
</a-select>
设置option-label-prop="label"文本框赋值的时候使用的是a-select-option的label属性,然后在a-select-option中就可以实现加入选中的标识了。