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)
    }
  • 相关阅读:
    mysql错误Error(1133): Can’t find any matching row in the use
    xtrbackup备份mysql
    配置Mysql审计
    Mysql:sql语句
    mysql基准测试与sysbench工具
    tomcat排错以及优化
    nginx反向代理
    Nginx
    服务器归分第一篇
    Android安装BusyBox(三星N7108)
  • 原文地址:https://www.cnblogs.com/xiaozhumaopao/p/7612246.html
Copyright © 2011-2022 走看看