首页 > js如何“链式”地调用fetch函数

js如何“链式”地调用fetch函数

我想fetch一个数据之后根据返回的数据再fetch,如何写最简洁?


fetch(`USER_URL`)
  .then(response => response.json())
  .then(user => fetch(`PROFILE_URL/${user.id}))
  .then(response => response.json())
  .then(profile => /* do whatever you want */)
  .catch(error => /* handle any errors */);

async load(){

let a = await fetch('url')
let id = await a.json()
let b = await fetch('id')
}
【热门文章】
【热门文章】