From 29832ba3f89dfd485205de5d5cf71ac444d0d76c Mon Sep 17 00:00:00 2001 From: Yotam Date: Mon, 8 Oct 2018 05:56:02 +0300 Subject: [PATCH] Added example of using $nextTick with async await (#1750) Added an example of using $nextTick with the async await syntax --- src/v2/guide/reactivity.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/v2/guide/reactivity.md b/src/v2/guide/reactivity.md index d538c2b23..8a0e808f3 100644 --- a/src/v2/guide/reactivity.md +++ b/src/v2/guide/reactivity.md @@ -119,3 +119,18 @@ Vue.component('example', { } }) ``` + +Since `$nextTick()` returns a promise, you can achieve the same as the above using the new [ES7 async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) syntax: + +``` +... + methods: { + async updateMessage: function () { + this.message = 'updated' + console.log(this.$el.textContent) // => 'not updated' + await this.$nextTick() + console.log(this.$el.textContent) // => 'updated' + } + } +... +```