提问者:小点点

关于fetch函数[重复]


我正在node.js中为MongoDB数据库构建一个API,并使用fetch函数查询外部API,但是当代码运行时,fetch函数返回以下内容:promise{}

我需要做什么才能返回请求的数据?

null

let requisicaoGetSummoner = function(summonerName) {
  let summonerGet = fetch('https://br1.api.riotgames.com/lol/summoner/v4/summoners/by-name/' + summonerName + '?api_key=' + api_key)
    .then(response => response.json())
    .then(data => {
      return data
    })
    .catch(err => console.log(err));
  return summonerGet
}

null


共1个答案

匿名用户

返回提取。

let requisicaoGetSummoner = function(summonerName){
  return fetch('https://br1.api.riotgames.com/lol/summoner/v4/summoners/by-name/' + summonerName + '?api_key=' + api_key)
  .then(response => response.json())
  .then(data => {
    return data
  })
  .catch(err => console.log(err));
}