The practice is as follows:

  • First question: although applets are not supported, we can introduce JS library. Download runtime.js from ‘packages/ regenerator-Runtime ‘and put it in the utils or lib folder of your own applets project.

  • Second question: the use of Async and Await

  • Async – Define Async function someName(){… })

    • Automatically converts the function to a Promise
    • When an asynchronous function is called, the return value of the function is resolved
    • Async functions can use await internally
  • Await – suspend execution of asynchronous functions (var result = Await someAsyncCall();)

    • When used before a Promise, await waits for the Promise to complete and returns the result of the Promise
    • Await can only be used with promises, not callback
    • Await can only be used in async functions
import regeneratorRuntime from '.. /.. /utils/runtime.js'

onLoad: function() {
    this.initData();
  },

  async initData(){ await this.initMyData(); // request interface 1 await this.initTodayData(); 2} initMyData:function(){
	console.log('Start request 1')... // Call console.log()"Complete Request 1")
	
	
}

  initTodayData:function(){
	console.log('Start request 2')... // Call console.log()"Complete Request 2")}Copy the code

  • He Yongfeng is a web front-end development engineer of Reed Technology. He likes to look for delicious food everywhere. His hobbies are dancing, playing basketball, listening to music, and sometimes attending some large dance performance events. And representative works: cute chicken drive, the United States travel small program, e-sports table small program. Good at website construction, public account development, wechat small program development, small games, public account development, focus on front-end domain framework, interaction design, image drawing, data analysis and other research, visit www.talkmoney.cn to learn more.