Last active
September 10, 2020 16:01
-
-
Save emmanuelbarturen/7535aa212bfefd7390cf4dee80ae8aed to your computer and use it in GitHub Desktop.
Api Calls Queue with Vuejs 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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