欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解小程序原生使用ES7 async/await語(yǔ)法

 更新時(shí)間:2018年08月06日 10:32:04   作者:Airmusic  
這篇文章主要介紹了詳解小程序原生使用ES7 async/await語(yǔ)法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

小程序原生使用ES7 async / await 語(yǔ)法

小程序開發(fā)工具-詳情-開啟ES6轉(zhuǎn)ES5

下載 regenerator 庫(kù) https://github.com/facebook/regenerator

將庫(kù)中packages文件夾下 regenerator-runtime 文件夾全部復(fù)制到小程序項(xiàng)目中

小程序項(xiàng)目全局引入 regenerator 庫(kù)

在app.js中引入

const regeneratorRuntime = require('./libs/runtime-module.js')

使用方法

Page({

 /**
  * 頁(yè)面的初始數(shù)據(jù)
  */
 data: {
  num: 0
 },

 /**
  * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
  */
 async onLoad(options) {
  this.testing()
  this.promiseFn()
  await this.testAsync()
 },

 

 testing() {
  console.log('test')
 },

 promiseFn() {
  this.testPromise().then((res) => {
   console.log(res)
  })
 },

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

 async testAsync() {
  const result = await this.testPromise()
  console.log('async test--', result)
 }
})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論