我正在使用npm软件包请求对URL进行获取请求。 https://www.npmjs.com/package/request
在请求完成后,如果我用console.log()将其运行良好。但是函数getToday()不返回任何内容,因为在未完成请求时它已经返回了。如何更改它以返回通话数据?
getToday() {
let date = new Date();
date = this.formatDate(date);
request(this.url + date, (error, response, body) => {
if (error) {
console.error(`error: ${error}`);
console.log('statusCode: ', response &&
response.statusCode); // Print the response status code if a response was received
}
this.match = this.regexp.exec(body)[0];
});
return this.match;
}