Creating the shopping cart
We've rendered some basic products now and given them an add to cart button.
Let's now make it so that when a user clicks the button the products show up in the shopping cart list.
Cart array
Back in our Vue instance, let's add a new data property called cart
. It'll just be assigned an empty array, as obviously the cart will need to be empty when the app first loads.
public/script.js
data() {
return {
...
cart: []
}
},
Click to load comments...