fetch 添加请求头headers

// var headers = new Headers();
    // headers.append('Authorization', localStorage.getItem('token'));
    fetch('/distributor/sidebar',{
      headers:{
        'Authorization':localStorage.getItem('token')
      }
    }).then(response => {
      return response.json();  // 先将结果转换为 JSON 对象
    })
    .then(data => {
      console.log(data);
      this.setState({
        name:data.info.dealer_name,
        phone:data.info.username
      });
    }).catch(function(error){
       console.log(error);
    });

  

原文地址:https://www.cnblogs.com/winyh/p/7515011.html