// 更新對應的狀态
handleChange = (name, val) => {
// 更新狀态
this.setState({
[name]: val // 屬性名不是name, 而是name變量的值
})
};
<InputItem placeholder='請輸入使用者名' onChange={val => {this.handleChange('username', val)}}>使用者名:</InputItem>
<InputItem placeholder='請輸入密碼' type="password" onChange={val => {this.handleChange('password', val)}}>密碼:</InputItem>
這裡寫了個 handleChange 事件,分别将傳入的 username password 更新為對應狀态。
其中 InputItem 是 antd-mobile 裡的,感興趣的可以去看看。