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) => {
|
const options = props.options.filter((option) => {
|
||||||
return option.label
|
if (option.label) {
|
||||||
.toLocaleLowerCase()
|
return option.label
|
||||||
.includes(keyword.toLocaleLowerCase());
|
.toLocaleLowerCase()
|
||||||
|
.includes(keyword.toLocaleLowerCase());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (props.allowCreate) {
|
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 = () => {
|
const enableAutoSelect = () => {
|
||||||
if (!selectProps.autoSelect) {
|
if (!selectProps.autoSelect) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -575,11 +587,6 @@ watch(
|
||||||
() => options.value,
|
() => options.value,
|
||||||
async (newOptions) => {
|
async (newOptions) => {
|
||||||
if (newOptions && newOptions.length > 0) {
|
if (newOptions && newOptions.length > 0) {
|
||||||
const selectedOption = await fetchSelectedOptions();
|
|
||||||
if (selectedOption) {
|
|
||||||
selectOptions.value = selectedOption;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableAutoSelect()) {
|
if (enableAutoSelect()) {
|
||||||
// Automatically select the first option when the selected value is empty.
|
// Automatically select the first option when the selected value is empty.
|
||||||
const autoSelectedOption = getAutoSelectedOption();
|
const autoSelectedOption = getAutoSelectedOption();
|
||||||
|
|
Loading…
Reference in New Issue