我如何从第一个url获取值,并将该值传递给第二个url参数?



我是新来学快递的。我尝试从第一个url获取值,并将该值传递给第二个url参数?

router.get('/',  function(req, res, next){
const teamId = ''
var player_data = {
method: 'GET',
url: 'https://sofascore.p.rapidapi.com/teams/get-player-statistics',
params: {teamId: '', tournamentId: '7', seasonId: '29267', type: 'overall'},
};
axios.request(team_data)
.then(function (response) {
const teamId = response.data.teams[0].id
console.log(teamId)
//axios.request(player_data)
//   .then(function (response){
//     const players = response.topPlayers.goals
//     res.render('index',{players: players})
//   })
})          
})

输出
[nodemon] restarting due to changes...
[nodemon] starting `node ./bin/www`
[nodemon] restarting due to changes...
[nodemon] starting `node ./bin/www`
3427

它正确地返回那个团队给我,但为什么我把id传递给第二个url来获得团队成员呢?

output
params: {
teamId: '',
tournamentId: '7',
seasonId: '29267',
type: 'overall'
},
....
'user-agent': [ 'User-Agent', 'axios/0.21.4' ],
host: [ 'Host', 'sofascore.p.rapidapi.com' ]
}
},
data: '400 - Bad Request'
},
isAxiosError: true,
toJSON: [Function: toJSON]

您需要将teamId放入player_data.params对象中。

axios.request(team_data)
.then(function(response) {
const teamId = response.data.teams[0].id
console.log(teamId)
player_data.params.teamId = teamId
axios.request(player_data)
.then(function(response) {
const players = response.topPlayers.goals
res.render('index', {
players: players
})
})
})
})

相关内容

  • 没有找到相关文章

最新更新