every thing work in my code, the problem is that this.loading=false run before the for() is done sending all the requests.
How can make this.loading=false get executed only after the for() finishes sending all the requests ?
i hope you got the idea.
methods:{
fileChange(event){
this.loading=true
//code
for(var i=0; i < tasks.length; i++){
//code
axios.post('/api/operation', data)
.then(response=>{
this.operations.push(name:response.data.name});
})
}
//i want to the bellow code to be executed after for() is finnished!
this.loading=false
},
},
>Solution :
use async/await
methods: {
async fileChange(event) {
this.loading = true
for (let i = 0; i < tasks.length; i++) {
const {data} = await axios.post('/api/operation', data) // << whats data?
this.operations.push({ name: data.name })
}
this.loading = false
},
},