[Vuejs]-How to access the promise result from the HTML in Vuejs

0👍

You do not have to use async,try this:

setIcon: function(id) {
    DataService.getFav().then((favs) = >{
        var isFav = favs.find((book) = >book.id === id);
        if (isFav === undefined) {
            return "favorite_border";
        } else {
            return "favorite";
        }
    })
}

if DataService.getFav() method has no params and get the same result, you should cache the result in the other method, otherwise each execute setIcon will call DataService.getFav(),it’s the waste of performance.

Leave a comment