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