如何将promise的结果返回到变量Promise {<pending>}?

时间:2019-06-19 17:54:04

标签: javascript typescript promise async-await es6-promise

我在将诺言的结果返回到变量时遇到问题。对我有用的唯一方法是制作console.log,但这不是我想要的。

const getAnimeVideo = async (id: string, chapter: number) => {
  const BASE_URL = `${url}${id}/${chapter}/`;
  const browser = await puppeteer.launch() ;
  const page = await browser.newPage();
  await page.goto(BASE_URL);
  const elementHandle = await page.$('.player_conte');
  const frame = await elementHandle.contentFrame();
  const video = await frame.$eval('#jkvideo_html5_api', el =>
    Array.from(el.getElementsByTagName('source')).map(e => e.getAttribute("src")));
  return video;
}

getAnimeVideo('tokyo-magnitude-80' , 1)
  .then(res => console.log(res)); // It shows me the data correctly.

const T = getAnimeVideo('tokyo-magnitude-80' , 1)
  .then(res => {
    return res; //Promise { <pending> }
  })

0 个答案:

没有答案