1. 程式人生 > >Ant Design Pro學習小結

Ant Design Pro學習小結

在models的effects中直接用setTimeout函式會報錯,例如以下錯誤寫法:

effects: {
  *update({ payload }, { call, put }) {
    const response = yield call(update, payload);
    if (response.status == "success") {
      message.success('成功!');
      setTimeout(()=>{
        yield put(routerRedux.push(`/xxx/xxx`));
      },2000)
    }
  }
}

解決方案:就是在這個modal自定義一個方法,並在effects裡呼叫settimeout方法

const delay = (ms) => new Promise((resolve) => {
  setTimeout(resolve, ms);
});

export default {
  namespace: 'aa',
  state: {},
  effects: {
    *update({ payload }, { call, put }) {
      const response = yield call(update, payload);
      if (response.status == "success") {
        message.success('成功!');
        setTimeout(()=>{
          yield put(routerRedux.push(`/xxx/xxx`));
        },2000)
      }
    }
  },
  reducers: {},
};