My goal is to have two buttons displayed when a user uploads data: one for old products and one for new products. When the user clicks on either button, the corresponding products will be uploaded as 'old_product' or 'new_product'. However, I encountered an error when attempting this:
_this.product[value].push is not a function
Below is the code snippet:
<template>
<div>
<input type="file" class="product_upload" id="product_upload" @change="previewFiles">
<button type="button" class="btn btn-primary" @click=uploadProduct('new_product')>New Product</button>
<button type="button" class="btn btn-primary" @click=uploadProduct('old_product')>Old Product</button>
</div>
</template>
<script>
export default {
data() {
return {
product: {
old_product: [],
new_product: []
}
}
},
methods: {
previewFiles(event){
return event.target.files;
},
uploadProduct(value){
let files = this.previewFiles;
this.product[value].push(files);
}
}
}
</script>