async,await简单用例

	async a(){
    
    
      const result = await this.b();
      // async 返回值会封装成一个promise
      return result
    },
    async b() {
    
    
        return 1
    }, 
    async test() {
    
    
      console.log(this.a()) //async 返回的是一个promise,打印:Promise {<pending>}
      this.a().then(res=>{
    
    
        console.log(res) //1
      })
    }, 

猜你喜欢

转载自blog.csdn.net/weixin_39818813/article/details/120262305
今日推荐