使用superagent调用API?

使用superagent调用API?,api,reactjs,superagent,Api,Reactjs,Superagent,我有一个API,它包含了这个数据分支 { “数据”:{ “id”:, “标题”:, “说明”:, “旧价格”:“100”, “新价格”:“50”, “尺寸”:“50”, “数量”:20, }, “错误”:空, “代码”:1 }对我来说,类似这样的方法很有效: import request from 'superagent'; getFooFromServer() { const url='http://...'; request.get(`${url}/foo`) .acce

我有一个API,它包含了这个数据分支

{
“数据”:{
“id”:,
“标题”:,
“说明”:,
“旧价格”:“100”,
“新价格”:“50”,
“尺寸”:“50”,
“数量”:20,
},
“错误”:空,
“代码”:1

}
对我来说,类似这样的方法很有效:

import request from 'superagent';

getFooFromServer() {
  const url='http://...';
  request.get(`${url}/foo`)
    .accept('json')
    .then(res => {
      //Do something with your data
    }
    catch(error => {
      //Do something with the error
    };
}
应该是

const title=response.body

很有可能

嘿,谢谢你,它成功了!当然,我做了一些调整,但这是一个起点)
const title=response.body