Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
TypeError: _vm.removeProductFromCart no es una función en vue/vuex

Estoy tratando de eliminar un artículo del carrito. Entonces debería poder eliminar el artículo con la identificación del carrito. Tengo un cartHelper y allí definí mi llamada api:

 removeFromCart: function (id, callback = undefined) { return apiHelper.deleteRequest( `/carts/${this.cookieValue}/remove-item`, (response) => { document.cookie = `${this.cartCookieName}=${response.data.attributes.cart_guid};`; if (callback) { callback(response); } }, { id: id } ) },

Y luego llamo a esta función en mi componente Cart:

 methods: { removeFromCart(id) { cartHelper.removeFromCart(id, () => { this.$store.dispatch('removeProductFromCart', id) }); }, },

Y definí mi acción como en el siguiente:

 export const removeProductFromCart = ({ commit }, id) => { commit('REMOVE_PRODUCT_FROM_CART', id); }

Y aquí está mi mutación:

 export const REMOVE_PRODUCT_FROM_CART = (state, id) => { state.cart = state.cart.filter(item => { return item.id !== id; }) }

Pero tan pronto como hago clic en el botón, donde estoy llamando a removeFromCart en mi componente Cart, obtengo "TypeError: _vm.removeProductFromCart is not a function" y no pude averiguar el motivo. Si puedes ayudarme, sería genial.

Versión editada --------- Aquí está mi estado:

 export default { cart: { "attributes": { "items": [], } }

Y mi index.js para la tienda:

 import Vue from 'vue'; import Vuex from "vuex"; Vue.use(Vuex); import state from "./state"; import * as getters from './getters'; import * as mutations from "./mutations"; import * as actions from "./actions"; export default new Vuex.Store({ state, getters, mutations, actions, }); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que ha estado llamando a removeProductFromCart en el evento @click que no existe en sus métodos. Intente llamar a removeFromCart en el evento @click.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!