2021-09-05

分享一个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
上一篇:【Linux题目】第五关


下一篇:oracle实战(一)