From 893ad57f7c4103378c118e4157bd2626dbb9e01c Mon Sep 17 00:00:00 2001 From: Aaron-zon <47178158+Aaron-zon@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:20:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=B8=AD=20json=20=E6=B3=95=E6=B7=B1=E6=8B=B7=E8=B4=9D?= =?UTF-8?q?=E6=8D=A2=E6=88=90=20lodash-es=20=E7=9A=84=20cloneDeep=20(#174)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/table/element-plus/index.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/views/table/element-plus/index.vue b/src/views/table/element-plus/index.vue index e971fcd9..6ab8ce81 100644 --- a/src/views/table/element-plus/index.vue +++ b/src/views/table/element-plus/index.vue @@ -5,6 +5,7 @@ import { type CreateOrUpdateTableRequestData, type GetTableData } from "@/api/ta import { type FormInstance, type FormRules, ElMessage, ElMessageBox } from "element-plus" import { Search, Refresh, CirclePlus, Delete, Download, RefreshRight } from "@element-plus/icons-vue" import { usePagination } from "@/hooks/usePagination" +import { cloneDeep } from "lodash-es" defineOptions({ // 命名当前组件 @@ -22,7 +23,7 @@ const DEFAULT_FORM_DATA: CreateOrUpdateTableRequestData = { } const dialogVisible = ref(false) const formRef = ref(null) -const formData = ref(JSON.parse(JSON.stringify(DEFAULT_FORM_DATA))) +const formData = ref(cloneDeep(DEFAULT_FORM_DATA)) const formRules: FormRules = { username: [{ required: true, trigger: "blur", message: "请输入用户名" }], password: [{ required: true, trigger: "blur", message: "请输入密码" }] @@ -45,7 +46,7 @@ const handleCreateOrUpdate = () => { } const resetForm = () => { formRef.value?.clearValidate() - formData.value = JSON.parse(JSON.stringify(DEFAULT_FORM_DATA)) + formData.value = cloneDeep(DEFAULT_FORM_DATA) } //#endregion @@ -67,7 +68,7 @@ const handleDelete = (row: GetTableData) => { //#region 改 const handleUpdate = (row: GetTableData) => { dialogVisible.value = true - formData.value = JSON.parse(JSON.stringify(row)) + formData.value = cloneDeep(row) } //#endregion