根据节点获取文档节点取
我们可以得到这样的响应状态
fetch('https://github.com/')
    .then(res => {
        console.log(res.status);
    });以及为了获取数据
fetch('https://api.github.com/users/github')
    .then(res => res.json())
    .then(jsonData => console.log(jsonData));我有一个场景,需要从响应返回JSON数据和状态。我试着用这种方法
     fetch('https://api.github.com/users/github')
            .then(res => res.json())
            .then(jsonData => {
             console.log(jsonData);
             console.log(jsonData.status);
      });但是
console.log(jsonData.status)
不会返回状态的。如何获得状态和输出数据
发布于 2018-08-22 19:54:25
另一种替代解决方案是使用Promise.all
fetch('https://api.github.com/users/github')
  .then(res => Promise.all([res.status, res.json()]))
  .then(([status, jsonData]) => {
    console.log(jsonData);
    console.log(status);
  });希望它能帮上忙
https://stackoverflow.com/questions/51973958
复制相似问题