账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    在react中 在setState方法的回调函数中能否再次调用setState方法?
    34
    0

    在componentWillMount中请求数据后,将拿到的数据setState操作后,在setState回调中能否再用state中的参数发起ajax请求后再将拿回的数据setState
    componentWillMount(){

    let appId = this.GetQueryString('appId')
    let language = this.GetQueryString('language')
    axios.post('/api/language/findAll').then(res=>{
      console.log('0000')
      for(let i=0;i<res.length;i++){
        if(res[i].en==language){
          this.setState({
            language:res[i].pid,
            appId:appId
          },()=>{
            this.queryConfig()
          })
        }
      }
    })

    }
    queryConfig(){

    let params={
      appId:this.state.appId,
      lang:this.state.language
    }
    axios.post('/api/spirit/config',params).then(res=>{
        console.log('第二个请求')
        this.setState({
          custom:res.spirit.custom,
          recommend:res.spirit.recommend,
          strategy:res.spirit.strategy,
        },()=>{console.log('第二次渲染')})
    })

    };

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部