异步请求,promise 必须配合Model里面方法return

2019-10-30  本文已影响0人  逸笛

需求:第一个请求的结果,需要作为第二个请求的请求参数

model 里面数据必须retrue返回,给页面使用


图片.png

执行第一个方法

  componentDidMount() {
    this.getChildAbilityDetail();
  }

第一个请求方法

//获取能力详情
  getChildAbilityDetail() {
    const currentId = localStorage.getItem('currentId');
    let { abilityId = '' } = this.props.location.state;
    const age = localStorage.getItem('age');
    this.props
      .dispatch({
        type: 'childAnalysis/getChildAbilityDetail',
        payload: { childId: currentId, age: age, testType: 1, kgid: 0, abilityId: abilityId },
      })
      .then(data => {
        this.getTaskTestStatus(data);
      });
  }

第二个请求方法

//获取能力详情

   //请求-获取状态
  getTaskTestStatus(childAbilityDetail) {
    const { dispatch } = this.props;
    const childId = localStorage.getItem('currentId');
    const {
      task: { taskid = '' },
    } = childAbilityDetail;
    dispatch({
      type: 'childAnalysis/getTaskTestStatus',
      payload: { childId: childId, taskIdList: taskid },
    });
  }
model里面方法,return  data:
    //能力详情页
    *getChildAbilityDetail({ payload }, { call, put }) {
      const {
        data: { data, code },
      } = yield call(getChildAbilityDetail, payload);
      if (code === 0) {
        yield put({
          type: 'updateListResult',
          payload: {
            childAbilityDetail: data,
          },
        });
        return data;
      }
    },
上一篇 下一篇

猜你喜欢

热点阅读