refactor: useForm => useResetReactive(同步 GiDemo 更新)

This commit is contained in:
2024-11-23 21:04:48 +08:00
parent be4356fa04
commit 6c45483fae
20 changed files with 53 additions and 38 deletions

View File

@@ -7,3 +7,4 @@ export * from './modules/useForm'
export * from './modules/useDevice'
export * from './modules/useBreakpoint'
export * from './modules/useDownload'
export * from './modules/useResetReactive'

View File

@@ -0,0 +1,15 @@
import { reactive } from 'vue'
import { cloneDeep } from 'lodash-es'
export function useResetReactive<T extends object>(value: T) {
const getInitValue = () => cloneDeep(value)
const state = reactive(getInitValue())
const reset = () => {
Object.keys(state).forEach((key) => delete state[key])
Object.assign(state, getInitValue())
}
return [state, reset] as const
}