wepy项目中使用async await

Gcaufy edited this page Jan 31, 2018 · 6 revisions

在1.4.1以后的版本,默认不支持async/await,需要用户手动加入,方法如下:

  • 进入项目根目录,安装runtime包
npm install wepy-async-function --save
  • 修改wepy.config.js加入runtime配置
        babel: {
            "presets": [
                "env"
            ],
            "plugins": [
                "transform-export-extensions",
                "syntax-export-extensions"
            ]
        }
  • 在app.wpy中引入引入runtime包
import 'wepy-async-function'; 
  • 在app.wpy中使API promise化
export default class extends wepy.app {

    constructor () {
        super();
        this.use('promisify');
    }

}
  • 重启编译
wepy build --no-cache
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.