feat: 字典标签支持取默认数据项
This commit is contained in:
@@ -15,14 +15,24 @@ const props = defineProps({
|
||||
type: [Number, String],
|
||||
default: '',
|
||||
},
|
||||
/**数据默认值,当前值不存在时 */
|
||||
valueOption: {
|
||||
type: [Number, String],
|
||||
},
|
||||
});
|
||||
|
||||
/**遍历找到对应值数据项 */
|
||||
const item = computed(() => {
|
||||
if (Array.isArray(props.options) && props.options.length > 0) {
|
||||
const option = (props.options as any[]).find(
|
||||
let option = (props.options as any[]).find(
|
||||
item => `${item[props.valueField]}` === `${props.value}`
|
||||
);
|
||||
// 数据默认值
|
||||
if (props.valueOption != undefined && !option) {
|
||||
option = (props.options as any[]).find(
|
||||
item => `${item[props.valueField]}` === `${props.valueOption }`
|
||||
);
|
||||
}
|
||||
return option;
|
||||
}
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user