perf: 优化 nestfield 重置不会变更的问题

This commit is contained in:
ibuler
2023-07-19 18:46:20 +08:00
parent b77440284f
commit e22ecb6fe8

View File

@@ -1,10 +1,13 @@
<template>
<DataForm
v-if="!loading"
:disabled="disabled"
:fields="iFields"
:form="value"
:form="form"
style="margin-left: -26%;margin-right: -6%"
v-bind="kwargs"
@change="form = $event"
@input="form = $event"
v-on="$listeners"
/>
</template>
@@ -37,6 +40,9 @@ export default {
},
data() {
return {
loading: false,
iForm: Object.assign({}, this.value),
formJson: JSON.stringify(this.value),
kwargs: {
hasReset: false,
hasSaveContinue: false,
@@ -45,6 +51,16 @@ export default {
}
},
computed: {
form: {
get() {
return this.iForm
},
set(val) {
this.iForm = Object.assign(this.iForm, val)
this.formJson = JSON.stringify(this.iForm)
this.$emit('input', this.iForm)
}
},
iFields() {
const fields = this.fields
if (this.errors && typeof this.errors === 'object') {
@@ -65,6 +81,21 @@ export default {
return fields
}
},
watch: {
value: {
handler(val) {
const valJson = JSON.stringify(val)
if (valJson !== this.formJson) {
this.loading = true
this.form = val
setTimeout(() => {
this.loading = false
})
}
},
deep: true
}
},
methods: {
objectToString(obj) {
let data = ''