错误
[Vue warn]: Invalid prop: custom validator check failed for prop "value".
错误复现:https://codesandbox.io/s/vue-...
确认是官方 bug
<template>
<a-select
:value="selectIdList"
placeholder="请选择讲师"
showSearch
:filterOption="false"
mode="multiple"
@search="search"
@change="change"
>
<a-select-option
v-for="{ id, name } of list"
:id="id"
:data-value="JSON.stringify({ userId: id, userName: name })"
:value="id"
:key="id"
>
{{ name }}
</a-select-option>
</a-select>
</template>
<script>
/**
* 课程讲师下拉框
* TODO 这个组件会导致 vue 警告,可能时 antd 的怪癖,不过不影响程序数据,可以暂且忽略
*/
export default {
name: 'MainSpeakerSelect',
model: {
prop: 'value',
event: 'change',
},
props: {
/**
* @type {MainSpeakerEntity[]}
*/
value: {
type: Array,
},
},
data() {
return {
//内部使用的 List 集合
selectIdList: [],
//全部的 List 选项
list: [],
}
},
created() {
this.search('')
},
watch: {
value(val) {
this.selectIdList = (val || []).map(({ userId }) => userId)
},
},
methods: {
async search() {
this.list = [
{ id: 1, name: '用户 谭磊', organization: 'aR5DPA', phone: '@phone' },
{ id: 2, name: '用户 高静', organization: 'WAh', phone: '@phone' },
{ id: 3, name: '用户 廖艳', organization: '9jvb', phone: '@phone' },
{ id: 4, name: '用户 张娟', organization: '(TX8', phone: '@phone' },
{id: 5, name: '用户 夏秀英', organization: 'rk#MsL5', phone: '@phone',},
{ id: 6, name: '用户 戴桂英', organization: '#ke6aX', phone: '@phone' },
{ id: 7, name: '用户 范平', organization: 'n7dp', phone: '@phone' },
{ id: 8, name: '用户 常霞', organization: 'AF0GP', phone: '@phone' },
{ id: 9, name: '用户 常艳', organization: 'ou1AQ', phone: '@phone' },
{ id: 10, name: '用户 方勇', organization: 'k7u0', phone: '@phone' },
]
},
change(selectIdList) {
const value = selectIdList.map(
id => JSON.parse(document.getElementById(id).dataset.value),
)
this.$emit('change', value)
},
},
}
</script>
去掉labelInValue