同步异步宏任务微任务
执行顺序:同步->异步(微任务->宏任务)
微任务:promise.then .catch .finally node's . nextTick
console.log('1')    //同步
setTimeout(function(){
 console.log('2')  //异步宏任务
},0)
new Promise((resolve)=>{
  console.log('3')   //同步  promise中的then finally catch才是异步
  resolve()
}).then(()=>{
  console.log('4')   //异步微任务
}).finally(()=>{
  console.log('5')    //异步微任务
})
console.log('6')   //同步
1,3,6,4,5,2
await关键词后面一搬跟一个promise对象
await会永远等到后面的promise进行resolve
await上方的代码是同步代码
export default { methods:{ async test(){ console.log(2) await new Promise(function (resolve,reject){resolve}) console.log(3) }, test1(){ console.log(1) this.test() console.log(4) } }
执行顺序 : 1,2,4,3
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号