async create() {
let formData = new FormData()
formData.append('name', this.name)
formData.append('size', JSON.stringify(this.size))
let copy = [...this.layers] // <==== HERE I TRY TO COPY
copy.forEach((layer, layerIndex) => {
layer.traits.forEach((trait, traitIndex) => {
if (!(trait.file instanceof Blob)) return
let name = `file_${layerIndex}_${traitIndex}`
formData.append(`images`, trait.file, name)
trait.file = name
})
})
formData.append('layers', JSON.stringify(copy))
try {
let result = await this.$axios.$post('/api/createcollection', formData)
this.$router.push('/dashboard')
} catch (err) {
this.layers = [...copy] // <==== HERE I RESET IT IF ITS FAIL
this.message = err.response.data
setTimeout(() => {
this.message = ''
}, 5000)
}
},
I am not able to set this.layers
to the way it was before. I have sent it, but for some reason, copy
is the same value as this.layers
Why this is copying
the same as this.layers
even if I spread it into a new array?