async await

Table of contents

1. Concept

2. The simplest way to write


1. Concept

They are all keywords;

Async await is used together to realize the synchronization of asynchronous operations;

They are syntactic sugar over promises, making asynchronous code easier to write and read;

await is only valid within the async function, if used outside its function, an error will be reported;

2. The simplest way to write

ps: You cannot directly write this in the method, because it is asynchronous, if you write this directly, then the point of this may not be what we want. It must be aliased before it can be used! ! !

let tableData=[];
async function temp(){
   let _this=this;
   let res =await Gerdata();//调接口
   _this.tableData=res;
   consoloe.log( _this.tableData)
}

Extension: same in setTimeout.

Guess you like

Origin blog.csdn.net/CMDN123456/article/details/130741410