【发布时间】:2018-07-04 16:47:57
【问题描述】:
我想将一个 API 请求中的参数值传递给第二个 API 请求,以便第二个 api 相应地显示结果:这是我的函数 componentWillMount:
componentWillMount() {
axios.post('https://APISITE/api/Auth/AuthorizeByApplication?applicationId=b72fc47a-ef82-4cb3-8179-2113f09c50ff&applicationSecret=e727f554-7d27-4fd2-bcaf-dad3e0079821&token=cd431b31abd667bbb1e947be42077e9d')
.then((response) => { console.log(response.data); });
axios.get('https://APISITE//api/Stock/GetStockItems',
{
params: {
keyWord: 454534534543,
locationId: '',
entriesPerPage: 100000,
pageNumber: 1,
excludeComposites: true,
//add other params
},
headers:
{ Authorization: 'asdfasdsfdfdfdfsfsdxxx'
}
//}).then((response) => { console.log(response.data); });
}).then((response) => this.setState({ products: response.data }));
axios.get('https://APISITE//api/Stock/GetStockLevel', {
params: {
stockItemId: '2f80b45c-85ff-449b-9ad6-ffcc4bb640dd',
},
headers:
{ Authorization: 'asdfasdsfdfdfdfsfsdxxx'
}
// }).then(response => console.log(response));
}).then((response) => this.setState({ racks: response.data }));
}
stockItemId 中的值作为静态值传递,结果正确显示在控制台中。如何从 1st-api 请求中动态获取 stockItemId 的值?
编辑:以下是直接在api中传递stockItemId并从第一个api获取的数据结果截图。
- 从第一个 api 获取:
stockItemId: stockItems.data.StockItemId:http://prntscr.com/i7k0j7 - 直接传递stockItemId的值截图-
stockItemId: '2f80b45c-85ff-449b-9ad6-ffcc4bb640dd'http://prntscr.com/i7jyq7
【问题讨论】:
标签: react-native parameter-passing axios