📜  获取然后返回值 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:23.478000             🧑  作者: Mango

代码示例1
function getvals(){
    return fetch('https://jsonplaceholder.typicode.com/posts',
    {
        method: "GET",
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
    })
    .then((response) => response.json())
    .then((responseData) => {
      console.log(responseData);
      return responseData;
    })
    .catch(error => console.warn(error));
  }
  
  getvals().then(response => console.log(response));