其他分享
首页 > 其他分享> > 2021-09-05

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

标签:console,log,05,AddUser,09,state,focusFn,2021,BlurFn
来源: https://blog.csdn.net/qq_46134549/article/details/120122845