[Vuejs]-How can i return a promise or wait for require?

0đź‘Ť

You can do this:

1. Create a Promise

    var promise = new Promise(function (resolve, reject) {
        // do a thing, possibly async, then…

        if (/* everything turned out fine */) {
            resolve("Stuff worked!");
        }
        else {
            reject(Error("It broke"));
        }
    });

2. Using the Promise

    promise.then(function(result) {
       console.log(result); // "Stuff worked!"
    }, function(err) {
       console.log(err); // Error: "It broke"
    });

I hope be useful!

Leave a comment