mirror of
				https://github.com/continew-org/continew-admin-ui.git
				synced 2025-10-31 22:57:15 +08:00 
			
		
		
		
	refactor: useForm => useResetReactive(同步 GiDemo 更新)
This commit is contained in:
		| @@ -7,3 +7,4 @@ export * from './modules/useForm' | ||||
| export * from './modules/useDevice' | ||||
| export * from './modules/useBreakpoint' | ||||
| export * from './modules/useDownload' | ||||
| export * from './modules/useResetReactive' | ||||
|   | ||||
							
								
								
									
										15
									
								
								src/hooks/modules/useResetReactive.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/hooks/modules/useResetReactive.ts
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
		Reference in New Issue
	
	Block a user