mha
mha

Reputation: 637

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

I have a function that does 2 things. I want to wait for the first line and then execute the second line. The first line is a simple assignment. How can I do this using async-await without making the first assignment a function. The following code gives me an error in line 2.

async eg(){
    await a = b;
    c.focus();
}

Upvotes: 0

Views: 1009

Answers (2)

ChrisWong
ChrisWong

Reputation: 30

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

Code Sandbox

Upvotes: 2

mha
mha

Reputation: 637

As user Al-un mentioned using this.$nextTick(); solved it beautifully.

Upvotes: 1

Related Questions