美文网首页
泛微常用react

泛微常用react

作者: deanwin | 来源:发表于2022-10-09 12:14 被阅读0次

1、动态绑定className

模板字符串<p className={`title ${this.state.addColor?'color':null}`}>标题</p>

<p className={['title',this.state.addColor?'color':null].join(' ')}>标题</p>

2、动态绑定style

 style={{color: index == this.state.monthIndex || dayObject.className == 'today' ? '#2c3b72':''}}

3、动态控制Style

  style={{ display: this.state.showElem ? "block" : "none" }}

4、map下面的点击事件{

失效的点击事件

onClick={this.setElem}

因为map循环的时候内部的this指向改变了

1、箭头函数,适用于一次map循环例如 onClick={()=>this.reservation()}

2、render定义this,将this转换成为_this.shiyong用nClick={()=>_this.reservation(item)

  render() {

     let _this =this

     this.state.Mettinglist.map(function (item, index) {

              return (

                <div  className="meeting-home-content-item-lxd" key={index}  onClick={()=>_this.reservation(item)}>

                </div>

              );

            })

}

相关文章

网友评论

      本文标题:泛微常用react

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