小程序如何支持使用 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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM