export function getUserInfo (username: string, password: string) {
return (dispatch: any) => {
return fetchUser(username, password)
.then(res => {
dispatch({
type: GET_USER_INFO,
userInfo: res
})
})
.catch(err => {
console.log(err)
})
}
}
export function getStars (username: string, password: string) {
return (dispatch: any, getState: any) => {
const url = getState().url
fetchStars(url, username, password)
.then(res => {
dispatch({
type: GET_STARS,
stars: res
})
})
.catch(err => {
console.log(err)
})
}
}
其中 getStars
依赖 getUserInfo
返回的数据,但是我不想把 getStars
放进 getUserInfo
的 then
方法中, 那样就把两个 action
揉到一起了, 想问问大家有没有什么好的解决方案。
请求写成回调的形式:
然后把后一个请求方法放在前一个请求方法的callback里