SoFunction
Updated on 2025-03-01

Detailed explanation of the native use of ES7 async/await syntax for applets

The applet uses ES7 async/await syntax natively

Mini Program Development Tools-Details-Open ES6 to ES5

Download the regenerator library/facebook/regenerator

Copy all the regenerator-runtime folders in the library packages folder to the applet project

The regenerator library is introduced globally by mini program projects

Introduced in

const regeneratorRuntime = require('./libs/')

How to use

Page({

 /**
   * Initial data of the page
   */
 data: {
  num: 0
 },

 /**
   * Lifecycle function-listen to page load
   */
 async onLoad(options) {
  ()
  ()
  await ()
 },

 

 testing() {
  ('test')
 },

 promiseFn() {
  ().then((res) => {
   (res)
  })
 },

 testPromise() {
  return new Promise((resolve, reject) => {
   setTimeout(() => {
    ('Promise handle')
    resolve(123)
   }, 2000)
  })
 },

 async testAsync() {
  const result = await ()
  ('async test--', result)
 }
})

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.