我正在對yelp-fusion. 但是,當我嘗試記錄此結果時,日志顯示為未定義。我認為這是由于有關承諾或異步函式的原因。注意:我需要將它保存在一個函式中,因為我打算將此函式匯出到其他檔案。
const searchRequest = {
term:'cafe',
location: 'san francisco, ca'
};
const client = yelp.client(apiKey);
function businessSearch(search){
client.search(search).then(response => {
return response
}).catch(e => {
console.log(e);
});
}
console.log(businessSearch(searchRequest))
uj5u.com熱心網友回復:
我認為您在這里正確處理了承諾。但是,您沒有從函式回傳任何內容,然后當您控制臺記錄其輸出時,您應該得到未定義。
試試這個:
function businessSearch(search){
return client.search(search).then(response => {
return response
}).catch(e => {
console.log(e);
});
}
console.log(businessSearch(searchRequest))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/460121.html
標籤:javascript 打字稿 http 拿来 喊叫
