Skip to content

Instantly share code, notes, and snippets.

@xdump
Created February 8, 2019 05:38
Show Gist options
  • Select an option

  • Save xdump/15ff5f99c0e6ddff07482bbd75aeb54b to your computer and use it in GitHub Desktop.

Select an option

Save xdump/15ff5f99c0e6ddff07482bbd75aeb54b to your computer and use it in GitHub Desktop.
vue async await methods
methods: {
waitFor: async function (ms) {
await new Promise(r => setTimeout(r, ms))
},
asyncForEach: async function (array, callback) {
for (let i = 0; i < array.length; i++) {
await callback(array[i], i, array);
}
},
start: async function () {
await this.asyncForEach(this.phrases, async (phrase) => {
await this.waitFor(1000);
console.log(phrase)
});
console.log('Done')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment