mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): error when options is empty
This commit is contained in:
parent
cca428aac6
commit
0186219586
@ -26,6 +26,7 @@ import {
|
|||||||
findOptionByValue,
|
findOptionByValue,
|
||||||
formatCascadeColumns,
|
formatCascadeColumns,
|
||||||
getFirstEnabledOption,
|
getFirstEnabledOption,
|
||||||
|
assignDefaultFields,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
// Composables
|
// Composables
|
||||||
@ -82,17 +83,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
linkChildren();
|
linkChildren();
|
||||||
|
|
||||||
const fields = computed(
|
const fields = computed(() => assignDefaultFields(props.columnsFieldNames));
|
||||||
(): Required<PickerFieldNames> =>
|
|
||||||
extend(
|
|
||||||
{
|
|
||||||
text: 'text',
|
|
||||||
value: 'value',
|
|
||||||
children: 'children',
|
|
||||||
},
|
|
||||||
props.columnsFieldNames
|
|
||||||
)
|
|
||||||
);
|
|
||||||
const optionHeight = computed(() => unitToPx(props.optionHeight));
|
const optionHeight = computed(() => unitToPx(props.optionHeight));
|
||||||
const columnsType = computed(() =>
|
const columnsType = computed(() =>
|
||||||
getColumnsType(props.columns, fields.value)
|
getColumnsType(props.columns, fields.value)
|
||||||
@ -128,7 +119,9 @@ export default defineComponent({
|
|||||||
selectedValues.value.forEach((value, index) => {
|
selectedValues.value.forEach((value, index) => {
|
||||||
const options = currentColumns.value[index];
|
const options = currentColumns.value[index];
|
||||||
if (!options.find((option) => option[fields.value.value] === value)) {
|
if (!options.find((option) => option[fields.value.value] === value)) {
|
||||||
selectedValues.value[index] = options[0][fields.value.value];
|
selectedValues.value[index] = options.length
|
||||||
|
? options[0][fields.value.value]
|
||||||
|
: undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { isDef, clamp } from '../utils';
|
import { isDef, clamp, extend } from '../utils';
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import type { PickerOption, PickerColumn, PickerFieldNames } from './types';
|
import type { PickerOption, PickerColumn, PickerFieldNames } from './types';
|
||||||
|
|
||||||
@ -95,3 +95,16 @@ export function isValuesEqual(
|
|||||||
valuesA.every((value, index) => value === valuesB[index])
|
valuesA.every((value, index) => value === valuesB[index])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function assignDefaultFields(
|
||||||
|
fields: PickerFieldNames | undefined
|
||||||
|
): Required<PickerFieldNames> {
|
||||||
|
return extend(
|
||||||
|
{
|
||||||
|
text: 'text',
|
||||||
|
value: 'value',
|
||||||
|
children: 'children',
|
||||||
|
},
|
||||||
|
fields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user