How can I execute the sortOrder
function as soon as the getOrders
function finishes all requests?
I thought about using a callback , but without success, any suggestions of a promise or code that uses callback?
Currently my code looks like this:
mounted () {
this.user = this.$q.localStorage.get.item('userInfo')
axios.get('${api.getOrders}${this.user.cpf}').then(response => {
this.orders = response.data
if (this.orders !== '') {
this.$q.loading.show()
this.getOrders(callback => {
this.sortOrder()
})
}
})
},
methods: {
getOrders: function () {
for (let i = 0; i < this.orders.length; i++) {
axios.get(api.obterOrderInfo(this.orders[i].orderId)).then(response => {
this.orderInfo = this.orderInfo.concat(response.data)
})
}
},
sortOrder: function () {
this.orderInfo.sort(this.compare)
this.$q.loading.hide()
},
compare: function (x, y) {
return x.creationDate < y.creationDate
}
}