簡體   English   中英

在 Vuejs 中使用 async-await 等待函數內的賦值

[英]using async-await to wait for an assignment inside a function in Vuejs

我有一個功能可以做兩件事。 我想等待第一行,然后執行第二行。 第一行是一個簡單的賦值。 我怎樣才能使用 async-await 做到這一點而不使第一次分配成為一個函數。 下面的代碼在第 2 行給了我一個錯誤。

async eg(){
    await a = b;
    c.focus();
}
eg() {
  this.a = this.b;
  setTimeout(() => {
    this.$refs["c"].focus();
  }, 1);
}

代碼沙盒

正如用戶 Al-un 提到的,使用this.$nextTick(); 漂亮地解決了它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM