feat(form): select动态监听事件优化

This commit is contained in:
parisma 2022-09-08 17:32:44 +08:00 committed by jia000
parent 7020ab4a1f
commit 040d5d0d2c

View File

@ -26,7 +26,7 @@
</template>
<script lang="ts">
import { defineComponent, inject, onBeforeMount, onMounted, PropType, Ref, ref, watch } from 'vue';
import { defineComponent, inject, onBeforeMount, onMounted, PropType, Ref, ref, watchEffect } from 'vue';
import { FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
import { getConfig } from '../utils/config';
@ -264,35 +264,24 @@ export default defineComponent({
};
if (typeof props.config.options === 'function') {
watch(
() => mForm?.values,
() => {
typeof props.config.options === 'function' &&
Promise.resolve(
props.config.options(mForm, {
model: props.model,
prop: props.prop,
formValues: mForm?.values,
formValue: mForm?.values,
config: props.config,
}),
).then((data) => {
options.value = data;
});
},
{
deep: true,
immediate: true,
},
);
watchEffect(() => {
typeof props.config.options === 'function' &&
Promise.resolve(
props.config.options(mForm, {
model: props.model,
prop: props.prop,
formValues: mForm?.values,
formValue: mForm?.values,
config: props.config,
}),
).then((data) => {
options.value = data;
});
});
} else if (Array.isArray(props.config.options)) {
watch(
() => props.config.options,
() => {
options.value = props.config.options as SelectOption[] | SelectGroupOption[];
},
{ immediate: true },
);
watchEffect(() => {
options.value = props.config.options as SelectOption[] | SelectGroupOption[];
});
} else if (props.config.option) {
onBeforeMount(() => {
if (!props.model) return;