異步編程

2020-05-12 17:47 更新
Taro 2.x 版本中使用 async-await 不再需要 @tarojs/async-await。

Taro 支持使用 async functions 來(lái)讓開發(fā)者獲得不錯(cuò)的異步編程體驗(yàn),開啟 async functions 支持需要安裝包 babel-plugin-transform-runtime 和 babel-runtime。

$ yarn add babel-plugin-transform-runtime --dev
$ yarn add babel-runtime

隨后修改項(xiàng)目 babel 配置,增加插件 babel-plugin-transform-runtime。

babel: {
  sourceMap: true,
  presets: [
    [
      'env',
      {
        modules: false
      }
    ]
  ],
  plugins: [
    'transform-decorators-legacy',
    'transform-class-properties',
    'transform-object-rest-spread',
    ['transform-runtime', {
      "helpers": false,
      "polyfill": false,
      "regenerator": true,
      "moduleName": 'babel-runtime'
    }]
  ]
}
值得注意的事,使用 async functions 一定要記得按照開發(fā)前注意中提示的內(nèi)容進(jìn)行操作,否則會(huì)出現(xiàn)報(bào)錯(cuò)


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)