text: import React from 'react';
  
  class CommentInput extends React.Component{
      constructor(){
          super();  //获得父类的实例，子类才能获得this
          this.state = {
              titleAppName:'react 留言板',
              userName:'',
              content:'',
          }
      }
  
      submitBtnFn(){
          // console.log('xxx');
          // this.setState({
          //     titleAppName:666
          // })
          // console.log(this.state.userName);
          // console.log(this.state.content);
  
          // 获得父组件传来的方法并向其中传值
          this.props.arrObjFn({
              userName:this.state.userName,
              content:this.state.content,
          })
      }
  
      // 用户名
      userNameFn(_valObj){
          // console.log('这是userName的函数');
          // console.log(_valObj.target.value);
          this.setState({
              userName:_valObj.target.value
          })
      }
  
      // 评论内容
      contentFn(_valObj){
          this.setState({
              content:_valObj.target.value
          })
      }
  
      render(){
          return <div className = 'comment-input'>
              <h1>应用名： {this.state.titleAppName}</h1>
              <div className='comment-field'>
                  <span className='comment-field-name'>用户名：</span>
                  <div className='comment-field-input'> <input type='text' 
                      onChange={this.userNameFn.bind(this)}
                      /></div>
              </div>
  
              <div className='comment-field'>
                  <span className='comment-field-name'>评论内容：</span>
                  <div className='comment-field-input'> <input
                      type='text' 
                      onChange={this.contentFn.bind(this)}
                  /></div>
              </div>
  
              {/* .bind(n) 就是将 n 传入到调用它的函数中去 */}
              <div className='comment-field-button'>
                  <button onClick={this.submitBtnFn.bind(this)}>发布按钮</button>
              </div>
          </div>
      }
  }
  
  export default CommentInput;