I am trying to vue.set() an array in a "updateInformation" mutation in my vuex store.
Here is my function in my script:
updateImagesArrayInMutation(imageFile) {
let images = [];
this.images.forEach(imageFile => {
imageFile.generateBlob(
blob => {
let rand = (Math.random().toString(36).substring(2, 16) + Math.random().toString(36).substring(2, 16)).toUpperCase()
let imagesRef = firestorage.ref('postimages/' + rand)
console.log("imageRef, imageFile for eachfile", imageFile)
if(this.images.length < 3) {
// THIS PUSHES AN EMPTY CROPPA ("CLICK DRAGE IMAGE HERE") // max 5
this.images.push({})
console.log("imagesRef", imagesRef.fullPath)
}
this.updateImages ({
images: imagesRef.fullPath
})
},
'image/jpeg',
0.8,
)
})
},
updateImages(images) {
console.log("this is value from closure", images)
this.updateInformation({
images: images,
title: this.post.title,
description: this.post.description
})
},
This is the mutation in my store:
[UPDATE_INFORMATION] (state, info) {
console.log('[STORE MUTATIONS] - UPDATE_INFORMATION:', info)
Vue.set(state.newPost.images, 'images', [...info.images])
// state.newPost.images = info.images
state.newPost.title = info.title
state.newPost.description = info.description
state.newPost.location = info.location
state.newPost.city = info.city
},
Can I do this? Thank you in advance for any suggestions.
newPostobject when your store is created?imagesproperty inside animagesproperty? I'd guess you just wantVue.set(state.newPost, 'images', [...info.images]).info.imagesis not an array. Difficult to know what to suggest without knowing why you're trying to spread a non-array into an array. Ifimagesis just a string then why are you involving arrays at all?