Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
export const qtyInCart = state => { const found = state.cart.added.find( p => p.id === id) if (!found){ return 0 } else return found.quantity }
import { qtyInCart } from './qtyInCart.js' qtyInCart(param)
var qtyInCart = require("./qtyInCart.js")(param)
<template> <ul> <li class="product product-item" v-for="p in products"> <div unit-left> <!--<img :src="'/dist/' + p.picture" class="product-picture">--> </div> <div class="unit-body"> <h2 class="product-name">{{p.title}}</h2> <p class="product-description">{{p.description}}</p> </div> <div unit-right> <span>{{p.price}}</span> <button class="add-button" @click="addToCart(p)" v-if="qtyInCart == 0">Заказать</button> <div v-else> <button class="inc" @click="addToCart(p)">+</button> {{qtyInCart(p)}} <button class="dec" @click="removeFromCart(p)">-</button> </div> </div> </li> </ul> </template> <script> import { mapGetters, mapActions } from 'vuex' export default { computed: mapGetters({ products: 'allProducts', qtyInCart: 'qtyInCart' }), methods: mapActions([ 'addToCart', 'removeFromCart', 'qtyInCart' ]), created () { this.$store.dispatch('getAllProducts') } } </script>
myMutation: (state, payload) => {...} // для mutations myAction: (context, payload) => {...} // для actions