vue-async 修饰created,created及mounted内代码执行顺序

async created() {
  this.name = await getHttpRequest()
  console.log(this.name, 'this.name')
},
mounted() {
   console.log('mounted')
   this.init();
 }

//输出结果

// mounted
// aa, 'this.name'

可以发现,在created 中被await 修饰的代码,执行顺序都在mounted内部同步代码之后。因此如果在mounted用到name是读取不到赋值之后的值。

你可能感兴趣的:(vue.js,javascript,前端)