我有这样的场景,用户在下拉列表中选择一个团队,这会向端点发送一个请求。
const selectHomeTeamStat = evt => {
const { value } = evt.target;
getStats(leagueId, value, 'home');
};
假设请求被发送到=> https://www.api-football.com/demo/api/v2/statistics/524/40
我希望能够在我的action.js
中创建一个多个请求,只需在url
的末尾添加一个date参数,如下所示:
从https://www.api-football.com/demo/api/v2/statistics/524/40
中,请求必须自动发送到以下三个端点
https://www.api-football.com/demo/api/v2/statistics/524/40/2019-08-30
,https://www.api-football.com/demo/api/v2/statistics/524/40/2019-09-30
https://www.api-football.com/demo/api/v2/statistics/524/40/2019-10-30
我的问题是如何在我的action.js
中发送这些多个请求?当用户从我的下拉列表中选择一个团队时,我如何使用这3个urls创建一个数组?
这就是我的getStats
应该做的
export function getStats(league, team, type) {
return function(dispatch) {
let URLs= ["https://www.api-football.com/demo/api/v2/statistics/524/40/2019-08-30",
"https://www.api-football.com/demo/api/v2/statistics/524/40/2019-09-30",
"https://www.api-football.com/demo/api/v2/statistics/524/40/2019-10-30"]
const getAllData = (URLs) => {
return Promise.all(URLs.map(fetchData));
}
const fetchData = (URL) => {
return axios
.get(URL)
.then(res => { ......
发布于 2020-04-20 05:26:09
const url = "https://www.api-football.com/demo/api/v2/statistics";
let dates = ["2019-08-30", "2019-09-30", "2019-10-30"]
const getAllData = (dates, i) => {
return Promise.all(dates.map(x => url + '/' + league + '/' + team + '/' + x).map(fetchData));
}
const fetchData = (URL) => {
return axios
.get(URL)
.then(res => {
https://stackoverflow.com/questions/61306995
复制相似问题