perf: improve api-component for using in form (#5796)
This commit is contained in:
parent
a77bb8e68d
commit
3c2d325d8c
@ -84,7 +84,7 @@ const emit = defineEmits<{
|
|||||||
const modelValue = defineModel({ default: '' });
|
const modelValue = defineModel({ default: '' });
|
||||||
|
|
||||||
const attrs = useAttrs();
|
const attrs = useAttrs();
|
||||||
|
const innerParams = ref({});
|
||||||
const refOptions = ref<OptionsItem[]>([]);
|
const refOptions = ref<OptionsItem[]>([]);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
// 首次是否加载过了
|
// 首次是否加载过了
|
||||||
@ -175,8 +175,15 @@ async function handleFetchForVisible(visible: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const params = computed(() => {
|
||||||
|
return {
|
||||||
|
...props.params,
|
||||||
|
...unref(innerParams),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.params,
|
params,
|
||||||
(value, oldValue) => {
|
(value, oldValue) => {
|
||||||
if (isEqual(value, oldValue)) {
|
if (isEqual(value, oldValue)) {
|
||||||
return;
|
return;
|
||||||
@ -189,12 +196,22 @@ watch(
|
|||||||
function emitChange() {
|
function emitChange() {
|
||||||
emit('optionsChange', unref(getOptions));
|
emit('optionsChange', unref(getOptions));
|
||||||
}
|
}
|
||||||
|
const componentRef = ref();
|
||||||
|
defineExpose({
|
||||||
|
/** 获取被包装的组件实例 */
|
||||||
|
getComponentRef: <T = any,>() => componentRef.value as T,
|
||||||
|
/** 更新Api参数 */
|
||||||
|
updateParam(newParams: Record<string, any>) {
|
||||||
|
innerParams.value = newParams;
|
||||||
|
},
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<component
|
<component
|
||||||
:is="component"
|
:is="component"
|
||||||
v-bind="bindProps"
|
v-bind="bindProps"
|
||||||
:placeholder="$attrs.placeholder"
|
:placeholder="$attrs.placeholder"
|
||||||
|
ref="componentRef"
|
||||||
>
|
>
|
||||||
<template v-for="item in Object.keys($slots)" #[item]="data">
|
<template v-for="item in Object.keys($slots)" #[item]="data">
|
||||||
<slot :name="item" v-bind="data || {}"></slot>
|
<slot :name="item" v-bind="data || {}"></slot>
|
||||||
|
Loading…
Reference in New Issue
Block a user