我正在使用redux saga实现登录,该登录saga可以正常工作,直到我发布以下错误信息:“操作必须是普通对象。对异步操作使用自定义中间件。
为什么会出现此错误?,一切正常。
我的传奇故事如下:
function* loginWithEmailSaga(payload) {
const headerParams = {
'Content-Type': 'application/json'
};
const apiCall = () => axios.post(route, {
username: payload.email,
password: payload.password
},
{ headerParams },
).then(response => response.data)
.catch(err => {
console.log(err);
});
try {
const data = yield call(apiCall);
console.log(data);
if (data.success) {
yield put(loginWithEmailSuccess(data.data));
yield history.push('/app');
}
} catch (error) {
console.log(error);
yield put(loginWithEmailFailure(error));
}
}
我的动作是这样的
export const loginWithEmail = (email, password) => ({
type: types.LOGIN_WITH_EMAIL_REQUEST,
email,
password
});
export const loginWithEmailSuccess = credential => ({
type: types.LOGIN_WITH_EMAIL_SUCCESS,
credential:credential.data
});
export const loginWithEmailFailure = error => ({
type: types.LOGIN_WITH_EMAIL_FAILURE,
error
});
redux的历史如下: