import { useState } from "react" /** * 使用表单 * @param props */ export default function useForm(initialState: any) { const [state, setState] = useState(initialState); function setFormState(...key: any) { console.log(key,'...val...val') setState(currentState => { var newState = { ...currentState }; for (var m = 0; m < key.length; m = m + 2) { newState[key[m]] = key[m + 1]; } return newState }) } return [state, setFormState, setState]; }
//文件中引入
import useForm from '@/components/ospmodel/useForm' //使用 const [lhys, setLhys] = useForm({// startTime: new Date(),//开始时间 F_NOTE: '',//节点名称 currentNodeData: null, }) 修改 setLhys("startTime", new Date());