博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
async/await with webpack+babel in Browser
阅读量:7292 次
发布时间:2019-06-30

本文共 1507 字,大约阅读时间需要 5 分钟。

1.安装以下插件

  • babel-plugin-transform-runtime
  • babel-preset-stage-3

2.Webpack配置

module : {       loaders : [{           test: /\.jsx?$/,           exclude: /node_modules/,           loader: 'babel-loader',            query: {                "presets": ["react", "es2015", "stage-0"]                "plugins": [                    ["transform-runtime", {                        "polyfill": false,                        "regenerator": true                    }]                ]            },       }]    }

3.调用实例

let fetchApi = () => {       return new Promise((resolve, reject) => {           var xhr = new XMLHttpRequest();           xhr.onreadystatechange = function() {               if (xhr.readyState === 4) {                   if (xhr.status >= 200 && xhr.status < 300) {                       var response;                       try {                           response = JSON.parse(xhr.responseText);                       } catch (e) {                           reject(e);                       }                       if (response) {                           resolve(response, xhr.status, xhr);                       }                   } else {                       reject(xhr);                   }               }           };           xhr.open('GET', 'https://api.douban.com/v2/user/aisk', true);           xhr.setRequestHeader("Content-Type", "text/plain");           xhr.send(xhr);       })   }  let testAsync = async () => {      const t = await fetchApi()      console.log(t)   }   testAsync()

转载地址:http://jzwnm.baihongyu.com/

你可能感兴趣的文章
JAVA调用返回XML格式数据的WebService,并通过XPath解析XML的应用
查看>>
虚拟机windows中编译环境的分辨率能否固定
查看>>
Python-函数
查看>>
全排列
查看>>
android音乐播放器(2)
查看>>
iOS presentedViewController的基本使用
查看>>
LNMP整合安装Redmine2.3实录
查看>>
易宝典文章——怎样管理Exchange Server 2013安全组
查看>>
erlang 简单例子的编译运行
查看>>
HyperV 中Windows Server 2012 非共享存储的在线迁移
查看>>
安装 CentOS 7 后必做的七件事
查看>>
myeclipse安装pydev
查看>>
【桌面虚拟化】之五PCoIP
查看>>
linux 监控CPU memory disk process 脚本
查看>>
Nginx启动脚本/etc/init.d/nginx
查看>>
Visual Studio 2017 离线安装方式
查看>>
枚举出局域网上所有网络资源
查看>>
Android深入浅出之Binder机制
查看>>
动态磁盘的管理
查看>>
zookeeper 集群安装(单点与分布式成功安装)
查看>>