我如何使用axios发送新请求,直到axios.all()响应尚未到来。我有三种类型的请求需要在应用程序首次加载时加载。在每个api响应之后,我想使用这些api响应数据发送一个新请求。
这是我的代码,该错误返回网络错误500
export function appInitialize(navigator) {
return async function (dispatch) {
dispatch({ type: APP_INITIALIZE });
axios.all([
api.get('appload'),
api.get('admin-settings'),
axios.get('https://example.com/api/ipinfo')
]).then(axios.spread((appLoadRes, adminSettingsRes, ipRes) => {
dispatch({
type: APP_INITIALIZED,
payload: {
appload: appLoadRes.data.response.data,
adminSettings: adminSettingsRes.data.response.data,
ip: ipRes.data.ip
}
});
dispatch(changeAppRoot('after-login'));
getUser().then(user => {
if (user) {
dispatch(changeAppRoot('after-login'));
api.get(`user/${user.id}`, {
headers: {
'Authorization': `Bearer ${user.token}`,
'Ip': ipRes.data.ip
}
}).then(response => {
dispatch({ type: USER_MANAGED, payload: response.data })
})
navigator.resetTo({
screen: 'navigation.Dashboard'
})
} else {
navigator.resetTo({
screen: 'navigation.Login'
})
}
})
}))
};
}