Jsx语法

作者: ZhongQw | 来源:发表于2018-06-30 22:21 被阅读8次
    在jsx文件里写style:
    style = {{display : 'none'}}
    
    组件类中添加proptype
    static propTypes = {
          comment: PropType.object.isrequired
    }
    
    组件对象添加state属性
    state = {
          comment:[
              xxx
              ...
      ]
    }
    
    将数组变为标签

    数组中的标签必须要有一个key

    comment.map((c,index) => <CommenItem comment = {c} key = {index} />)
    
    一个自定义的方法

    由于this

    this
    handleSubmit {
    }
    
    • 箭头函数(没有自己的this,会从外围(全局)找)
    constructor(props){
            this.handleClick = this.handleClick.bind(this);
            //通过bind方法产生一个新的函数,且函数体和handleClick一样
    
            handleSubmit = ( ) => {
            }
    }
    

    相关文章

      网友评论

        本文标题:Jsx语法

        本文链接:https://www.haomeiwen.com/subject/grlqeftx.html