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);
    });

  

posted @ 2017-09-13 15:03  winyh  阅读(21211)  评论(0编辑  收藏  举报