fix: #451
This commit is contained in:
parent
f977fdb05d
commit
08665a35ac
|
@ -5,7 +5,7 @@
|
|||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
"[vue]": {
|
||||
"editor.defaultFormatter": "Vue.volar"
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"i18n-ally.localesPaths": ["src/locales"],
|
||||
"i18n-ally.keystyle": "nested",
|
||||
|
|
|
@ -143,6 +143,7 @@ export const setItemComponentSlots = (slotsProps: Recordable = {}): Recordable =
|
|||
*/
|
||||
export const initModel = (schema: FormSchema[], formModel: Recordable) => {
|
||||
const model: Recordable = { ...formModel }
|
||||
console.log('【model】:', model)
|
||||
schema.map((v) => {
|
||||
if (v.remove) {
|
||||
delete model[v.field]
|
||||
|
@ -158,5 +159,12 @@ export const initModel = (schema: FormSchema[], formModel: Recordable) => {
|
|||
// model[v.field] = hasField ? model[v.field] : v.value !== void 0 ? v.value : undefined
|
||||
}
|
||||
})
|
||||
// 如果 schema 对应的 field 不存在,则删除 model 中的对应的 field
|
||||
Object.keys(model).forEach((key) => {
|
||||
const isExist = schema.some((item) => item.field === key)
|
||||
if (!isExist) {
|
||||
delete model[key]
|
||||
}
|
||||
})
|
||||
return model
|
||||
}
|
||||
|
|
|
@ -407,6 +407,11 @@ setTimeout(async () => {
|
|||
const formData = await getFormData()
|
||||
console.log(formData)
|
||||
}, 2000)
|
||||
|
||||
const getData = async () => {
|
||||
const formData = await getFormData()
|
||||
console.log(formData)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -451,6 +456,7 @@ setTimeout(async () => {
|
|||
<BaseButton @click="inoutValidation">
|
||||
{{ `${t('formDemo.input')} ${t('formDemo.formValidation')}` }}
|
||||
</BaseButton>
|
||||
<BaseButton @click="getData"> 获取值 </BaseButton>
|
||||
</ContentWrap>
|
||||
<ContentWrap :title="`UseForm ${t('formDemo.example')}`">
|
||||
<Form :schema="schema" @register="formRegister" @validate="formValidate" />
|
||||
|
|
Loading…
Reference in New Issue