ProductList.vue 537 B

1234567891011121314151617181920212223242526272829303132
  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 { getAllProducts, addToCart } from '../vuex/actions'
  16. export default {
  17. vuex: {
  18. state: {
  19. products: ({ products }) => products.all
  20. },
  21. actions: {
  22. getAllProducts,
  23. addToCart
  24. }
  25. },
  26. created () {
  27. this.getAllProducts()
  28. }
  29. }
  30. </script>