Answer the question
In order to leave comments, you need to log in
How to access file upload status in Vue.js + axios, from another component?
I have a service component for working with api (ApiManager.js) , it has a method for uploading files:
uploadImage(imagFormData) {
return axios.post('https://apiurl/image', imagFormData, {
headers: {
"Authorization": "Client-ID"
},
onUploadProgress: uploadedEvent => {
console.log('Upload proccess -> ', Math.round(uploadedEvent.loaded / uploadedEvent.total * 100) , '%' )
}
})
.then(response => {
console.log('uploaded resp ---> ', response);
})
}
import ApiManager from '@/services/ApiManager'
ApiManager.uploadImage(imagFormData).then(response =>{
...
})
Answer the question
In order to leave comments, you need to log in
onUploadProgress({loaded, total}) {
const uploadProgress = Math.round(loaded / total * 100)
store.commit('uploader/setProgress', uploadProgress)
}
export const uploader = {
namespaced: true,
state: {
progress: 0
},
mutations: {
setProgress(state, progress) {
state.progress = progress
}
}
}
computed: {
...mapState('uploader', [
'progress'
])
}
<template>
<div>{{progress}}%</div>
</template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question