zoukankan      html  css  js  c++  java
  • react总结

    1:<JDText style={[styles.tips,this.state.bgColor?{backgroundColor:'green'}:{backgroundColor:'yellow'}]}>{this.state.contentSecTip}</JDText>

    动态改变样式,this.state.bgColor在前,样式在后

    2:

    <JDText style={tips}>{this.state.contentSecTip}</JDText>

    tips为上面定义的变量样式

     3:react setstate 即时生效

    setState延迟更新的原因在于—state是异步执行的,只有render发生变化的时候才触发this.setState()。

    想要在不更新render的情况下立即执行(同步执行),需要在setState后加上一个function函数。 
    当然,render更新了之后对state的值没有任何影响。 
    现在只是说,在没有更新render的情况下,我们加上了function也能获取到state的值


    (二)具体解决方案:

    // 1.设置代码
    this.setState({
       myState: 'doubi'
       }, function() {
         // stateFunction是需要立即用到
         this.stateFunction()
       })
    // 2.在函数中直接调用
    stateFunction() {
       console.log('doubi', this.state.myState)
    }

    转载于:https://www.cnblogs.com/xiaozhumaopao/p/7612246.html

  • 相关阅读:
    均匀采样单位圆
    3Sum
    查看SQL语句在SQL Server上的执行时间
    ASP.NET页面请求处理
    原型模式
    ASP.NET页面错误处理
    电子商务推荐位商品模型设计
    HttpModule与HttpHandler使用
    装饰者模式
    ASP.NET编程模型
  • 原文地址:https://www.cnblogs.com/twodog/p/12139286.html
Copyright © 2011-2022 走看看