Skip to content

Commit

Permalink
refactor: 将项目中 json 法深拷贝换成 lodash-es 的 cloneDeep (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron-zon authored Mar 11, 2024
1 parent 5a2836c commit 893ad57
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/views/table/element-plus/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
// 命名当前组件
Expand All @@ -22,7 +23,7 @@ const DEFAULT_FORM_DATA: CreateOrUpdateTableRequestData = {
}
const dialogVisible = ref<boolean>(false)
const formRef = ref<FormInstance | null>(null)
const formData = ref<CreateOrUpdateTableRequestData>(JSON.parse(JSON.stringify(DEFAULT_FORM_DATA)))
const formData = ref<CreateOrUpdateTableRequestData>(cloneDeep(DEFAULT_FORM_DATA))
const formRules: FormRules<CreateOrUpdateTableRequestData> = {
username: [{ required: true, trigger: "blur", message: "请输入用户名" }],
password: [{ required: true, trigger: "blur", message: "请输入密码" }]
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 893ad57

Please sign in to comment.