• 利用 高阶函数 | 作用域 | 配置初始化脚本 的全局变量


    import context from '@utils/context';
    
    
    const configFileUrl = `http://sgs.com/api`;
    
    const timtOut = proObj => {
      return Promise.race([
        proObj,
        new Promise(resolve => {
          setTimeout(() => {
            resolve({ code: 1001, errMsg: '接口请求超时,时限3秒' });
          }, 3000);
        })
      ]);
    };
    const fetchApiPro = requestPromise({ url: configFileUrl });
    const h_fetchConfigFile = () => {
      let apiData = null;
      fetchApiPro.then(res => (apiData = res));
      return () => apiData;
    };
    
    const output = {
      init() {
        this._getConfigFile = h_fetchConfigFile();
      },
      getPreSaleConfig: async function () {
        const { preSaleListConfig } = this;
        if (preSaleListConfig) {
          return preSaleListConfig;
        }
        let res;
        try {
          res = await timtOut(fetchApiPro);
        } catch (e) {
          res = { code: 1001, errMsg: e };
        }
        return res;
      },
      get preSaleListConfig() {
        return output._getConfigFile();
      }
    };
    export default output;
  • 相关阅读:
    多线程之异步操作
    AppDomain
    多线程之线程同步
    webServices与Web服务
    webParts与Web部件
    xhtmlConformance与xhtml脚本呈现
    webControls与客户端脚本路径
    urlMappings与URL映射
    trace与代码跟踪服务
    siteMap与站点导航
  • 原文地址:https://www.cnblogs.com/liujinyu/p/12797811.html
Copyright © 2020-2023  润新知