【发布时间】:2020-02-25 14:56:31
【问题描述】:
这是我的 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);
}
【问题讨论】:
标签: reactjs api message-passing