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


    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;
  • 相关阅读:
    C++ istringstream总结
    C++各数据类型的最值
    AcWing 机器人跳跃问题 二分
    蓝桥杯 矩形面积交
    蓝桥杯 完美的代价
    蓝桥杯 数的读法
    国内 镜像 下载
    redis的pipline使用
    MySQL额外操作
    sql强化演练( goods 表练习)
  • 原文地址:https://www.cnblogs.com/liujinyu/p/12797811.html
Copyright © 2020-2023  润新知