1

有人可以帮我怎么做吗?那是我通过获取数据来获取数据的代码,我如何将其导出到另一个文件并对其进行查询并在 UI 中呈现它?
那就是代码:

const Cision = require('config');                 
   exports.createPressReleseasData = async (type = 'all') => {
    const listAPI = `${Cision.basePath}/papi/NewsFeed`;

    const format = `format=json`;
    let apiCall = '';
    let result = [];

    switch (type) {
      case 'press':
        apiCall = `${listAPI}/${Cision.en.pressReleases}?${format}`;
        break;
      case 'reports':
        apiCall = `${listAPI}/${Cision.en.reportReleases}?${format}`;
        break;
      case 'regulatory':
        apiCall = `${listAPI}/${Cision.en.regulatoryReleases}?${format}`;
        break;
      default:
        apiCall = `${listAPI}/${Cision.en.allReleases}?${format}`;
    }

    try {
      const response = await fetch(apiCall);
      const json = await response.json();

      result = json;
    } catch (e) {
      return 'Error', e;
    }
  };
4

0 回答 0