为了账号安全,请及时绑定邮箱和手机立即绑定

vue中 钩子函数如何使用async?

vue中 钩子函数如何使用async?

FFIVE 2018-07-21 22:29:54
  async created () {    await setTimeout(()=>{      console.log(1)     },5000);   },  async mounted () {    console.log(2)   }在vue中给created使用async await,还是会先输出2,而不是等1输出完?
查看完整描述

2 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

可以变相达到这个目的

  async created () {    this.create_promise = new Promise(resolve=>this.create_promise_resolve=resolve);
    setTimeout(()=>{        console.log(1);        this.create_promise_resolve();
    },1000)
  },  async mounted () {    await this.create_promise;    console.log(2)
  }


查看完整回答
反对 回复 2018-07-28
  • 2 回答
  • 0 关注
  • 4567 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信