`
222xiaohuan
  • 浏览: 50641 次
  • 性别: Icon_minigender_2
  • 来自: 苏州
社区版块
存档分类
最新评论

防止数据发返回时组件不存在(unmount)

阅读更多

1,  componentDidMount() {

    this.mounted = true;

  }

 

2,   componentWillUnmount() {

    this.mounted = false;

  }

 

3,fetchThisWeekData() {

    const params = {};

    params.flag = 0;

    Request.GET(API.getEmployeeAttendanceData(params), (responseData) => {

      if (!this.mounted) return;

      this.thisWeek = responseData;

      // console.log('thisweek----', this.thisWeek);

      // this.thisWeek = [[2, 2, 6], [3, 6, 2], [1, 0, 4], [0, 4, 6], [3, 6, 0], [0, 0, 0], [4, 4, 4]];

      if (Util.isAndroid) {

        this.setState({

          data: {

            datasets: [{

              yValues: this.thisWeek,

              label: '',

              config: {

                barSpacePercent: 60,

                colors: ['#56e295', '#617fde', '#f9bf13'],

                stackLabels: [`${I18n.t('regularHours')}`, `${I18n.t('overtime')}`, `${I18n.t('leave')}`],

                valueTextColor: 'white',

                valueTextFontSize: 6,

              },

            }],

            xValues: [`${I18n.t('monday')}`, `${I18n.t('tuesday')}`, `${I18n.t('wednesday')}`, `${I18n.t('thurday')}`, `${I18n.t('friday')}`, `${I18n.t('saturday')}`, `${I18n.t('sunday')}`],

          },

          loaded: true,

        });

      }

      if (Util.isIos) {

        this.state.config.dataSets[0].values = this.thisWeek;

        this.setState({

          config: this.state.config,

          loaded: true,

        });

      }

    }, (message) => {

      if (!this.mounted) return;

      Message.showMessage('error', message);

    });

  }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics