如题,如何处理redux-saga的回调,调用自己的方法,比如,执行了saga后清除表单的输入,或者弹出成功信息框,或者跳转页面等等import { call, put, takeLatest } from 'redux-saga/effects'import { fetch } from '@/util/request'import { message } from 'antd'import { push } from 'react-router-redux'import { CREATE_TASKGRAP, createTaskGrapSuccess, createTaskGrapFailed } from '../../actions/drawTaskGrapAction'const apifetch = (drawTaskGrap) => { return fetch('drawTaskGrap', drawTaskGrap)
}export function* DrawTaskGrapData(actions){ try{ yield takeLatest(CREATE_TASKGRAP, DrawTaskGrapData); const res = yield call(apifetch, actions.taskGrapObj); console.log('draw task grap saga = ', res);
yield put(createTaskGrapSuccess(res.data))
}catch(error){ yield put(createTaskGrapFailed(error.message))
}
}
2 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
我自己写了个解决方法:
this.props.dispatch(createTaskGrap({ task:{ activities: activities, remark: "", srcJson: modelTxt, templateName: "", }, // 声明你的方法,方法体里面的逻辑自己实现就好 testFn:()=>{ //your do } }))
然后在saga里面执行:
export function* DrawTaskGrapData(actions){ try{ yield takeLatest(CREATE_TASKGRAP, DrawTaskGrapData); const res = yield call(apifetch, actions.taskGrapObj.task); // 调用想要执行的方法 actions.taskGrapObj.testFn(); yield put(createTaskGrapSuccess(res.data)) }catch(error){ yield put(createTaskGrapFailed(error.message)) } }
添加回答
举报
0/150
提交
取消