工匠基地官网-last
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

29 lines
588 B

import { reactive } from 'vue';
/**
* 表单数据 hook
* @param initValue 默认值
*/
export default function <T extends object>(initValue?: T) {
const form = reactive<T>({ ...initValue } as T);
const resetFields = () => {
Object.keys(form).forEach((key) => {
form[key] = initValue ? initValue[key] : void 0;
});
};
const assignFields = (data: object) => {
Object.keys(form).forEach((key) => {
form[key] = data[key];
});
};
return {
form,
// 重置为初始值
resetFields,
// 赋值不改变字段
assignFields
};
}