12345678910111213141516171819202122232425262728293031 |
- <template>
- <ul>
- <li
- v-for="product in products"
- :key="product.id">
- {{ product.title }} - {{ product.price | currency }}
- <br>
- <button
- :disabled="!product.inventory"
- @click="addProductToCart(product)">
- Add to cart
- </button>
- </li>
- </ul>
- </template>
- <script>
- import { mapState, mapActions } from 'vuex'
- export default {
- computed: mapState({
- products: state => state.products.all
- }),
- methods: mapActions('cart', [
- 'addProductToCart'
- ]),
- created () {
- this.$store.dispatch('products/getAllProducts')
- }
- }
- </script>
|