下載 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
