Skip to content

Instantly share code, notes, and snippets.

@emmanuelbarturen
Last active September 10, 2020 16:01
Show Gist options
  • Save emmanuelbarturen/7535aa212bfefd7390cf4dee80ae8aed to your computer and use it in GitHub Desktop.
Save emmanuelbarturen/7535aa212bfefd7390cf4dee80ae8aed to your computer and use it in GitHub Desktop.
Api Calls Queue with Vuejs 2
const app = new Vue({
el: '#tool-app',
data() {
return {
tivs: [],
nextKey: 0
}
},
mounted() {
API.getAllTIV().then(response => {
return response.json();
}).then(json => {
this.tivs = json.images
this.getDecode();
});
},
methods: {
getDecode() {
if (this.tivs.length > this.nextKey) {
return API.getData(this.tivs[this.nextKey]).then(response => {
return response.json()
}).then(json => {
this.nextKey++
console.log(json)
}).catch(err => {
console.log(err)
this.nextKey++
});
} else {
console.log('no existe el key ' + this.nextKey + ' en ese arreglo')
}
}
},
watch: {
nextKey: function () {
this.getDecode()
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment