1
0

ProductList.vue 504 B

1234567891011121314151617181920212223242526272829
  1. <template>
  2. <ul>
  3. <li v-for="p in products">
  4. {{ p.title }} - {{ p.price | currency }}
  5. <br>
  6. <button
  7. :disabled="!p.inventory"
  8. @click="addToCart(p)">
  9. Add to cart
  10. </button>
  11. </li>
  12. </ul>
  13. </template>
  14. <script>
  15. import { mapGetters, mapActions } from 'vuex'
  16. export default {
  17. computed: mapGetters({
  18. products: 'allProducts'
  19. }),
  20. methods: mapActions([
  21. 'addToCart'
  22. ]),
  23. created () {
  24. this.$store.dispatch('getAllProducts')
  25. }
  26. }
  27. </script>