Created
February 8, 2019 05:38
-
-
Save xdump/15ff5f99c0e6ddff07482bbd75aeb54b to your computer and use it in GitHub Desktop.
vue async await methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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