老師 哪裡可以改善

来源:2-7 自由编程

weixin_慕雪0272820

2020-08-23 21:50:26

import React, { Component, Fragment } from 'react';

class Ref extends Component {
    constructor(props) {
        super(props);
        this.getContent = this.getContent.bind(this);
        this.state = {
            content:""
        }
    }


    getContent() {
        let content = this.inputElement.value
        console.log(content)
        this.setState({content})
    }

    render() {
        return (
            <Fragment>
                <input ref={(ref) => this.inputElement = ref}/><br/>
                <button onClick= {this.getContent}>提交</button>
            </Fragment>
            
        )
    }

}
export default Ref


写回答

1回答

好帮手慕言

2020-08-24

同学你好,效果是正确的,不用改善了,继续加油,祝学习愉快~

0

0 学习 · 10739 问题

查看课程