这是我的post api请求,我需要从前端获取此数据:
考虑下面的代码,users_id
实际上是从localStorage获取的,而items_id
是从我从componentDidMount
调用的另一个api中获取的]]
purchaseOrder(){ const Users_id = localStorage.getItem('id'); // get user_id const items_id = this.state.data.id; // get items_id console.log(Users_id) console.log(items_id) PostData('api/purchase-order-item/submit', this.state).then ((result) => { // how to pass the users id and items id to api? let responseJSON = result; console.log(responseJSON); console.log(this.state) }); }
this.state:
constructor(props){
super(props);
this.state ={
data: [],
remark: '', //for api
quantity: '', // for api
isLoaded: false,
redirect: false,
history: PropTypes.object.isRequired
}
this.purchaseOrder = this.purchaseOrder.bind(this);
this.onChange = this.onChange.bind(this);
}
这是我的发布api请求,我需要从前端获取此数据:考虑下面的代码,users_id实际上是从localStorage获取的,而items_id是从另一个被我称为api的api中获取的。
remark
和quantity
,然后传递一个新的普通对象作为API发布数据: