I got something like this:
methods: {
process: function process(id) {
this.$http.post('controller/process', { id: id }).then(function (res) {
if (res.data.items > 0) {
this.process(id);
} else {
return true;
}
}, function (data) {
this.$notify(data, 'danger');
this.progress = false;
});
},
run: function run($id) {
this.busy = true;
this.process($id);
this.busy = false;
}
},
Alright - this is some JavaScript using Vue.js and vue-resource to do am API call (process). The API returns the number of elements to be processed. If this number is > 0, the function should be executed again. This works fine.
Now I would like to solve the following:
Executing the run
function should set this.busy = true
. After the function process
is done processing all items, this.busy
should be set to false
.
So I read something about promises - but I still don't get how I could use them in this case.