分享一个React设置state值的另一种方法
import {Component} from "react";
import {Input} from "antd";
class AddUser extends Component{
state={
a:""
}
focusFn=(e)=>{
console.log(e)
this.setState({
a:"1212"
})
}
BlurFn=(e)=>{
console.log(e)
this.setState({
a:""
})
}
render() {
console.log(this.a)
const { a } = this.state;
return(
<>
<Input placeholder="Basic usage" onFocus={this.focusFn} onBlur={this.BlurFn} />
<label style={{color:"red"}}>{a}</label>
<Input placeholder="Basic usage" onFocus={this.focusFn} />
</>
)
}
}
export default AddUser