我想使用Fetch抓取数据后,返回抓取的数据,但是现在我调用postFromServer函数,无法等到Fetch,就直接返回一个undefined,请问如何解决这个问题?
module.exports = {
postFromServer ( requestParam ) {
const _self = this;
let url = requestParam['url'] || '';
let headers = requestParam['headers'] || '';
let postBody = requestParam['postBody'] || '';
let response = _self.sendToServer( url, 'POST', headers, postBody );
response.then(function(value) {
console.log('第三方 value === ', value)
if( value['code'] === 200 ) {
return value
}
}, function(error) {
console.log('第三方 error === ', error)
});
}
}
import Helper from 'common-helper-es6';
let receiveData = await Helper.postFromServer( requestParam );
加一个return就可以了