表单进入验证问题

This commit is contained in:
gary.fu
2024-01-10 16:32:24 +08:00
parent 804d47df3b
commit 6994f7c45a

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
import { $i18nBundle } from '@/messages' import { $i18nBundle } from '@/messages'
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
@@ -61,7 +61,11 @@ const props = defineProps({
} }
}) })
const initRules = () => { //= ============form暴露============//
const form = ref()
const rules = computed(() => {
const ruleResult = {} const ruleResult = {}
props.options.forEach(option => { props.options.forEach(option => {
if (option.prop) { if (option.prop) {
@@ -86,10 +90,9 @@ const initRules = () => {
} }
} }
}) })
form.value && form.value.clearValidate()
return ruleResult return ruleResult
} })
const rules = ref({})
const emit = defineEmits(['submitForm', 'update:model']) const emit = defineEmits(['submitForm', 'update:model'])
@@ -103,17 +106,12 @@ const initFormModel = () => {
} }
}) })
} }
rules.value = initRules()
} }
initFormModel() initFormModel()
watch(() => props.options, initFormModel, { deep: true }) watch(() => props.options, initFormModel, { deep: true })
//= ============form暴露============//
const form = ref()
defineExpose({ defineExpose({
form form
}) })