fetch response.json() gives responseData = undefined

前端 未结 6 862
青春惊慌失措
青春惊慌失措 2020-12-01 06:34

When using fetch:

  fetch(REQUEST_URL, {
      method: \'get\',
      dataType: \'json\',
      headers: {
        \'Accept\': \'application/json\',
             


        
6条回答
  •  Happy的楠姐
    2020-12-01 06:45

    fetch(weatherIng + zipCode +apiKey)
            .then(response => response.json())
    
          .then(response => {
         console.log(response.main);
         this.setState({
           weather: ((response.main.temp * (9/5))-459.67).toFixed(0),
           humidity:((response.main.humidity * (9/5))-459.67).toFixed(0)
         })
    

    It will think that you are trying to declare something if you don't enclose it in its own:

      .then(response => {
         console.log(response.main);
         }) . " around the this.setState
    

提交回复
热议问题