9. Working with Vuex – State, Getters, Actions, and Mutations
Activity 9.01: Creating a Simple Shopping Cart and Price Calculator
Solution:
Perform the following steps to complete the activity:
Note
To access the code files for this activity, refer to https://packt.live/2KpvBvQ.
- Create a new Vue application with Vuex support via the CLI.
- Add the products and empty
cart
to the store located instore/index.js
. Note that the product names and prices are arbitrary:Â Â state: { Â Â Â Â products: [ Â Â Â Â Â Â { name: "Widgets", price: 10 }, Â Â Â Â Â Â { name: "Doodads", price: 8 }, Â Â Â Â Â Â { name: "Roundtuits", price: 12 }, Â Â Â Â Â Â { name: "Fluff", price: 4 }, Â Â Â Â Â Â { name: "Goobers", price: 7 } Â Â Â Â ], Â Â Â Â cart...