Last active
October 31, 2020 23:51
-
-
Save vanholler/0fb75329cbb5f05992e4253ad6c8b43f to your computer and use it in GitHub Desktop.
This file contains 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
// in Actions: | |
uploadFile: ({ state, commit }, { file }) => { | |
return new Promise((resolve, reject) => { | |
Fetcher({ | |
url: endpoints.uploadFile, | |
method: 'POST', | |
headers: { | |
'Authorization': `${state.token}` | |
}, | |
onUploadProgress ({ loaded, total }) { | |
const uploadProgress = Math.round(loaded / total * 100) | |
commit('setPercentage', uploadProgress) | |
}, | |
data: { | |
file | |
} | |
}) | |
.then((resp) => { | |
resolve(resp) | |
}) | |
.catch((err) => { | |
console.log('upload error,', err) | |
reject(err.response) | |
}) | |
}) | |
} | |
// in muttations | |
setPercentage (state, num) { | |
state.percentage = num | |
} | |
// in state | |
percentage: '' | |
// in component | |
computed: { | |
percentage () { | |
return this.$store.state.percentage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment