I am using vue.js 2.* . I want to perform an action on an item but first, I check if this item exists and if not, I go fetch it through an API. My current code looks like this :
if (myItem == null) {
this.goFetchItem().then(response => {
myItem.performAction()
})
} else {
myItem.performAction()
}
I'd like to know if it possible to have somthing in the idea of :
if (myItem == null) {
this.goFetchItem()
}
//And then, when item is fetched :
myItem.performAction()
For now,,in the second example, it seems goFetchItem()
is executed asynchronoulsy, so myItem
is still null
when trying to perform the action.