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

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

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react componentDidMount 数据请求两次
    38
    0

    我在componentDidMount请求数据,然后在浏览器里看到我的数据请求了两次,在网上也找到一些答案,但是都没有解决问题。这是找到的一个回答:
    react-router3.x hashHistory render两次的bug,及解决方案
    然后在控制台打印出来 this.props.router.location.action发现两次都是POP
    并没有像上面链接说的那样一个是PUSH一个是POP,请问有人遇到这个问题么?是怎么解决的?
    数据请求:

      componentDidMount() {
        window.addEventListener('scroll', this.onScrollHandle);
        if (!this.state.isDraft) {
          this.props.getRate({type: this.state.type, userId: this.state.userId});
          this.handlePageChange(1, 3);
        }
        this.getData();
        console.log(this.props.router.location.action);
        // this.setState({provinceInfo: getProvinceInfo(this.state.provinceId)});
      }
    
      getData = () => {
        this.props.getApp(this.state.type, this.state.userId);
        this.props.getSimilarApp({ apptype: this.state.type });
      }

    react版本如下

    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-redux": "^4.4.2",
    "react-router": "^3.0.5",
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部