小程序如何支持使用 async/await

下载 regenerator-runtime

npm i regenerator-runtime

如何使用

在小程序中,不认识 node_modules 文件夹,无法通过以下方法来直接找到包文件

import regeneratorRuntime form 'regenerator-runtime'

所以需要将 regenerator-runtime 中的 runtime.js(支持async/await的核心文件) 拿出来存放到一个文件夹中,通过一般的文件引入方式使用。

例:

import regeneratorRuntime from '../../lib/runtime.js'

值得一提的是导出的名字必须为 regeneratorRuntime ,否则无法使用async/await

最后

使用过程中如果出现一些意外,我在构建npm版中有记录到一个碰到的错误

使用async/await(构建npm版): https://www.cnblogs.com/chanwahfung/p/11503533.html

猜你喜欢

转载自www.cnblogs.com/chanwahfung/p/11681881.html