In vuejs2 app I upload images which are selected in modal form and I want to close this modal form
only fg all images are saved ok(calling self.hidePhotosUploadingModal() method)
For this I set var uploaded_count and inc it on any success upload, but checking value of
uploaded_count I see it is NaN
savePhotosUploadingModal() {
let uploaded_count= 0
let self = this
this.imagePhotosUploadingFiles.map((nextImagePhotosUploadingFile, index) => {
fetch(nextImagePhotosUploadingFile.blob).then(function (response) {
if (response.ok) {
return response.blob().then(function (imageBlob) {
let imageUploadData = new FormData()
imageUploadData.append('image', imageBlob)
imageUploadData.append('image_filename', nextImagePhotosUploadingFile.name)
Window.axios.post('/profile/upload_photo', imageUploadData).then(({data}) => {
// self.uploaded_count // IF TO UNCOMMENT THIS LINE THAT DOES NOT WORK ANYWAY
self.uploaded_count = self.uploaded_count 1
console.log('self.uploaded_count::') // I SEE NaN IN BROWSER'S CONSOLE
console.log(self.uploaded_count)
if (self.uploaded_count === self.imagePhotosUploadingFiles.length) {
self.hidePhotosUploadingModal()
}
self.loadLoggedInactivePhotos()
}).catch((error) => {
console.error(error)
})
})
} else {
return response.json().then(function (jsonError) {
console.error(jsonError)
})
}
}).catch(function (error) {
console.error(error)
}) // fetch(nextImagePhotosUploadingFile.blob).then(function (response) {
}) // this.imagePhotosUploadingFiles.map((nextImagePhotosUploadingFile, index) => {
}, // savePhotosUploadingModal
How that can be fixed ?
Thanks!
CodePudding user response:
Try to cange self.uploaded_count to just uploaded_count
