define interface:
interface ILoginState { imageId: string; imageSrc: string; username: string; password: string; verifyCode: string; }
useState:
const [loginData, setLoginData] = useState(loginState)
update imageId && imageSrc:
setLoginData({ ...loginData, imageId: res.data.id. imageSrc: res.data.content })
antd inputchange:
onInputChange(e: FormEvent<HTMLInputElement>) { const inputName = e.currentTarget.id; const inputValue = e.currentTarget.value; setInputData({ [inputName]: inputValue } as {[key in keyof ILoginState]:ILoginState[key]}) }
原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/11230813.html
时间: 2024-10-07 18:04:27