我有一些代码需要更新。这不是我的代码,所以我不需要太多更改。它使用redux-saga和axios。我想将一些参数传递给佐贺
[export function* getInfoSaga() {
while (true) {
yield take(mutations.GET_INFO);
const url1 = `${url}/api/getInfo/1-100`;
const logInfo = yield axios.get<any>(url1).then(response => response);
yield put(mutations.setInfo(logInfo.data.data));
}
}
mutations.js
export const GET_INFO = 'GET_INFO';
export const getInfo = () => ({
type: GET_INFO,
});
sagas在中运行index.js
const s = sagas as any;
for (const saga in s) {
sagaMiddleware.run(s[saga]);
}
并且在某些文件中,操作由带有事件的按钮执行:
onClick={() => dispatch({
type: 'GET_INFO',
})}
[我想传递一些参数来修改请求的URL,我尝试在dipatch请求中获取其他对象,并在sagas.js和mutatuions.js中为生成器添加参数,但是我<出错。
我有一些代码需要更新。这不是我的代码,所以我不需要太多更改。它使用redux-saga和axios。我想在sagas.js导出函数中将一些参数传递给我的英雄传奇* ...
onClick={() => dispatch({
type: 'GET_INFO',
url: 'your/url/goes/here'
})}
export function* getInfoSaga(action) {
while (true) {
yield take(mutations.GET_INFO);
const url1 = `${action.url}/api/getInfo/1-100`;
const logInfo = yield axios.get<any>(url1).then(response => response);
yield put(mutations.setInfo(logInfo.data.data));
}
}