mirror of https://github.com/halo-dev/halo
[release-2.19] fix: resolve incorrect display of options in formkit selector with async data (#6631)
This is an automated cherry-pick of #6629 /assign LIlGG ```release-note 解决当 formkit select 组件中的 options 延迟设置时无法正常回显的问题。 ```pull/6633/head
parent
527a49e3b8
commit
a5ff816af5
|
@ -43,9 +43,12 @@ const filterOptions = computed(() => {
|
|||
}
|
||||
|
||||
const options = props.options.filter((option) => {
|
||||
return option.label
|
||||
.toLocaleLowerCase()
|
||||
.includes(keyword.toLocaleLowerCase());
|
||||
if (option.label) {
|
||||
return option.label
|
||||
.toLocaleLowerCase()
|
||||
.includes(keyword.toLocaleLowerCase());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (props.allowCreate) {
|
||||
|
|
|
@ -555,6 +555,18 @@ watch(
|
|||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => options.value,
|
||||
async (newOptions) => {
|
||||
if (newOptions && newOptions.length > 0) {
|
||||
const selectedOption = await fetchSelectedOptions();
|
||||
if (selectedOption) {
|
||||
selectOptions.value = selectedOption;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const enableAutoSelect = () => {
|
||||
if (!selectProps.autoSelect) {
|
||||
return false;
|
||||
|
@ -575,11 +587,6 @@ watch(
|
|||
() => options.value,
|
||||
async (newOptions) => {
|
||||
if (newOptions && newOptions.length > 0) {
|
||||
const selectedOption = await fetchSelectedOptions();
|
||||
if (selectedOption) {
|
||||
selectOptions.value = selectedOption;
|
||||
}
|
||||
|
||||
if (enableAutoSelect()) {
|
||||
// Automatically select the first option when the selected value is empty.
|
||||
const autoSelectedOption = getAutoSelectedOption();
|
||||
|
|
Loading…
Reference in New Issue