I want to push object into array inside data properties in my nuxt project. but i am getting error like
Cannot read properties of undefined (reading 'push')
here is my js part
<script>
export default {
data() {
return {
form: {
gallery: [{
id: null,
imgurl: null
}]
}
}
},
methods: {
async uploadGallery() {
var myimg = "imageurl getting after upload";
var imgData = {};
imgData['imgurl'] = myimg;
imgData['id'] = "someid";
this.form.gallery.push(imgData);
},
}
}
</script>
this.form.galleryisundefinedat some point. You probably have some async issues somewhere else in your code.imgData.imgurl, simpler.