Browse Source

perf: 表单设置初始值defaultValue时候使用深度拷贝

pull/1934/head
yfh01 4 years ago
parent
commit
a103cd11b4
  1. 3
      src/components/Form/src/hooks/useFormEvents.ts
  2. 4
      src/components/Form/src/hooks/useFormValues.ts

3
src/components/Form/src/hooks/useFormEvents.ts

@ -39,7 +39,8 @@ export function useFormEvents({
Object.keys(formModel).forEach((key) => {
const schema = unref(getSchema).find((item) => item.field === key);
const isInput = schema?.component && defaultValueComponents.includes(schema.component);
formModel[key] = isInput ? defaultValueRef.value[key] || '' : defaultValueRef.value[key];
const defaultValue = cloneDeep(defaultValueRef.value[key]);
formModel[key] = isInput ? defaultValue || '' : defaultValue;
});
nextTick(() => clearValidate());

4
src/components/Form/src/hooks/useFormValues.ts

@ -3,7 +3,7 @@ import { dateUtil } from '/@/utils/dateUtil';
import { unref } from 'vue';
import type { Ref, ComputedRef } from 'vue';
import type { FormProps, FormSchema } from '../types/form';
import { set } from 'lodash-es';
import { cloneDeep, set } from 'lodash-es';
interface UseFormValuesContext {
defaultValueRef: Ref<any>;
@ -124,7 +124,7 @@ export function useFormValues({
}
}
});
defaultValueRef.value = obj;
defaultValueRef.value = cloneDeep(obj);
}
return { handleFormValues, initDefault };

Loading…
Cancel
Save