react时时获取表单数据

import React, { Component } from "react";

export class TestHanderClick extends Component {
         constructor(props) {
           super(props);
           this.state = {
             cont: "内容哦",
           };
         }

         //时时获取input中的值,通过事件onChange;e.target.value来获取值
         changeCont(e) {
           this.setState({
             cont: e.target.value,
           });
         }

         render() {
           return (
             <div>
               <input
                 type="text"
                 value={this.state.cont}
                 onChange={this.changeCont.bind(this)}
               />
               <p>{this.state.cont}</p>
             </div>
           );
         }
       }

export default TestHanderClick;

获取表单中的值还可以参考这篇文章https://www.cnblogs.com/IwishIcould/p/11619473.html

posted @ 2020-08-17 23:15  何人陪我共长生  阅读(416)  评论(0编辑  收藏  举报