- async/await是一个ES7的语法,这个语法是回调函数的终极解决方案;
- 语法:
async function fn(){
const res = await Promise对象
}
- 这个是一个特殊的函数方式;async代表异步,await加在谁身上,谁先执行;
- 一般是把await加在promise对象前面才有意义,让异步的promise对象先执行;
- 让异步代码写的看起来像同步代码;
- 只要是一个promise对象,那么我们就可以使用async/await来书写;
async function test(){
try{
//await 同步代码/promise对象
var res = await pajax({
url:"http://localhost:3000/news",
data:{
author:"tiechui"
}
})
var res1 = await pajax({
url: "http://localhost:3000/comments",
data: {