i am making a product page and cart page, when i click on the Addtocart buton i want the product to be added to the cart page. Now i am wokring without a database so i just want to create an array of cart and when ever i click on the button the array is appended with that product
//this is product page
<template>
<div class="container">
//here i am listing the products
<div v-for="product in products" :key="product.id">
<div>
<h1>{{ product.name }}</h1>
//when i click this button i want to add the product the cart array, now to go to methods
<button @click="Add" class="button" >Add to cart</button>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'Product',
data () {
return {
products: [
{name: 'product1', description: 'preview text', id: '1'},
{name: 'prduct2', description: 'preview text 2', id: '2'}
],
cart: []
},
methods: {
//when i click the button here i have no idea how to add the product the cart
Add () {
this.$set(this.cart, 'name', 'product1')
}
}
}
</script>