Browse Source

fix: 优化表单项

wanggaokun 11 months ago
parent
commit
04a7d5850b
2 changed files with 8 additions and 9 deletions
  1. 8 2
      src/components/ProForm/components/Item.vue
  2. 0 7
      src/components/ProForm/index.vue

+ 8 - 2
src/components/ProForm/components/Item.vue

@@ -47,8 +47,14 @@ interface FormItem {
   model: any
 }
 const props = defineProps<FormItem>()
-const _model = computed(() => props.model)
-
+const _model = ref({})
+watch(
+  () => props.model,
+  () => {
+    _model.value = props.model
+  },
+  { immediate: true }
+)
 const elTagNameValue = computed(() => {
   const val = props.item.compOptions.elTagName
   if ('radio-button' == val) return `el-radio-group`

+ 0 - 7
src/components/ProForm/index.vue

@@ -152,19 +152,12 @@ watch(
   () => props.model,
   () => {
     props.itemsOptions.forEach((item: ProForm.ItemsOptions) => {
-      // const defaultValue = item.compOptions?.value
-      // if (defaultValue !== undefined && defaultValue !== null) {
-      //   props.model[item.prop] ? (props.model[item.prop] = defaultValue) : false
-      // }
-      console.log(item.compOptions.value === 0 ? 0 : item.compOptions.value)
-
       // 如果类型为checkbox,默认值需要设置一个空数组
       let value = ['checkbox', 'transfer'].includes(item.compOptions.elTagName!) ? [] : props.model[item.prop]
       props.model[item.prop]
         ? (formModel.value = props.model)
         : (formModel.value[item.prop] = item.compOptions.value === 0 ? 0 : item.compOptions.value || value)
     })
-    console.log(formModel.value)
   },
   { immediate: true }
 )