Ver código fonte

fix(Form组件): 修复defaultValue=0不生效的问题

shizhongming 2 anos atrás
pai
commit
700d5e8e9c
1 arquivos alterados com 5 adições e 1 exclusões
  1. 5 1
      src/components/Form/src/hooks/useFormEvents.ts

+ 5 - 1
src/components/Form/src/hooks/useFormEvents.ts

@@ -2,7 +2,7 @@ import type { ComputedRef, Ref } from 'vue';
 import type { FormProps, FormSchemaInner as FormSchema, FormActionType } from '../types/form';
 import type { NamePath } from 'ant-design-vue/lib/form/interface';
 import { unref, toRaw, nextTick } from 'vue';
-import { isArray, isFunction, isObject, isString, isDef, isNil } from '@/utils/is';
+import { isArray, isFunction, isObject, isString, isDef, isNil, isNumber } from '@/utils/is';
 import { deepMerge } from '@/utils';
 import {
   dateItemType,
@@ -377,6 +377,10 @@ function getDefaultValue(
   let defaultValue = cloneDeep(defaultValueRef.value[key]);
   const isInput = checkIsInput(schema);
   if (isInput) {
+    // TODO: 默认值0不生效问题解决
+    if (isNumber(defaultValue)) {
+      return defaultValue;
+    }
     return defaultValue || undefined;
   }
   if (!defaultValue && schema && checkIsRangeSlider(schema)) {