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