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是读取不到赋值之后的值。

Logo

前往低代码交流专区

更多推荐