fix: 表单复用列表行对象导致编辑时引用污染,引入 cloneDeep 深拷贝避免串数据

This commit is contained in:
Ray.Hao
2026-01-23 18:32:20 +08:00
parent 0e0a9d6365
commit 3879105e15

View File

@@ -134,6 +134,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useThrottleFn } from "@vueuse/core"; import { useThrottleFn } from "@vueuse/core";
import cloneDeep from "lodash-es/cloneDeep";
import type { FormInstance, FormRules } from "element-plus"; import type { FormInstance, FormRules } from "element-plus";
import type { IComponentType, IModalConfig, IObject } from "./types"; import type { IComponentType, IModalConfig, IObject } from "./types";
import InputTag from "@/components/InputTag/index.vue"; import InputTag from "@/components/InputTag/index.vue";
@@ -193,11 +194,11 @@ const handleClose = () => {
const setFormData = (data: IObject) => { const setFormData = (data: IObject) => {
for (const key in formData) { for (const key in formData) {
if (Object.prototype.hasOwnProperty.call(formData, key) && key in data) { if (Object.prototype.hasOwnProperty.call(formData, key) && key in data) {
formData[key] = data[key]; formData[key] = cloneDeep(data[key]);
} }
} }
if (Object.prototype.hasOwnProperty.call(data, pk)) { if (Object.prototype.hasOwnProperty.call(data, pk)) {
formData[pk] = data[pk]; formData[pk] = cloneDeep(data[pk]);
} }
}; };
// 表单提交 // 表单提交