Commit 3c2d325d by Netfan Committed by GitHub

perf: improve api-component for using in form (#5796)

1 parent a77bb8e6
...@@ -84,7 +84,7 @@ const emit = defineEmits<{ ...@@ -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) { ...@@ -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( ...@@ -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>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!