The issue encountered is a TypeError stating that _vm.removeProductFromCart is not recognized as a function within the Vue/V

I am currently facing an issue with deleting an item from the cart. In order to successfully remove the item from the cart, I need to utilize the item's ID. Within my cartHelper, I have defined the API call as follows:

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
            }
        )
    },

Subsequently, I invoke this function within my Cart component like so:

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

In addition, I have defined the action in the following manner:

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

And here is my mutation logic:

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

However, upon clicking the button linked to the removeFromCart function within my Cart component, I encounter the error message "TypeError: _vm.removeProductFromCart is not a function". I am at a loss as to why this error is occurring. Any assistance would be greatly appreciated.

Updated version--------- Here is an overview of my current state:

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

Furthermore, here is my index.js for the store:

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,
});

}

Answer №1

It appears you've been using the removeProductFromCart function on the @click event, but this function does not exist in your methods. Please use the removeFromCart function instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ever-evolving universal variable in Angular

I've been struggling to find the right search terms. Despite reading various resources, I can't seem to locate the specific solution I'm looking for. I'm certain there must be an innovative way to do this in Angular that I haven't ...

Design strategies for creating a sidebar menu with AngularJS directives

Currently exploring angularJS for the development of a simple side menu. I have a choice between two directive designs, and I'm facing a dilemma in picking the better one: Option 1 The HTML structure: <sidebar title="Sidebar Heading"> <s ...

How to use regular expressions to extract a specific query parameter from a URL

I am trying to extract the first character after "action/" in a URL similar to: server/area/controller/action/4/?param=2" The server could be one of the following: http://localhost/abc https://test.abc.com https://abc.om Is there a way to achieve this ...

Crushing a Marionette Controller in Backbone.js

I'm trying to figure out how to properly destroy a Marionette controller. As I delve into understanding Marionette and Backbone garbage collection, I'm encountering some hurdles... The controller in question creates multiple views, each potentia ...

Using the <noscript> tag for an individual element or a comparable alternative

So, I have a link labeled "Impressum" that when clicked, opens up the Impressum section. <a data-open="something">Impressum</a> <div class="reveal" id="something" data-reveal> <img src="images/reverseLogo.png"> <h1>Imp ...

What is the best way to trigger a controller action using jQuery in your application.js file?

Currently, I am incorporating the jQuery autocomplete plugin into my project and looking to personalize a specific event: select: function(event, ui) { $('.topic_field').val(ui.item.topic.name); return false; This event es ...

The challenge of combining card values in Black Jack

Having an issue with my function that's meant to add card values together. When I use the function with these arguments, it correctly logs 21. score([{ suit: 'HEARTS', value: 1 }, { suit: 'SPADES', value: 11 }]) //Logs 21 as it sho ...

Redirect in React Route

I've been researching how to programmatically redirect in React, but I'm struggling to get it to work. Here's a simplified version of my code: import React from 'react'; import {render} from 'react-dom'; import {Browser ...

Animating a progress bar with JQuery

Having issues with displaying a progress bar using jquery and javascript, as it is not appearing on the page. var show_time = Math.floor(Math.random() * 10000) + 5000; setTimeout(function() { $("#progress").hide() }, show_time); var myCountdown = $( ...

What is the best way to retrieve the input value from post.ejs?

app.js var express = require('express'); var bodyParser = require('body-parser'); var app = express(); var passport = require('passport'); var localStrategy = require('passport-local'); var axios = require("axi ...

Is there a way to identify the subdocument ids that have been updated in Mongoose when performing an

Is there a reliable way to retrieve the _id of subdocuments that are inserted into an array within my document using doc.updateOne? I am concerned about getting incorrect _id values when multiple updates occur. This is my current approach, but I'm wo ...

What is the reason behind the one-way functionality of underscore's difference method?

If I asked you, "What separates these two arrays: ['a'] and ['a', 'b']?" your answer would be 'b', correct? I'm curious why underscore doesn't automatically provide bidirectional diff functionality. How ca ...

What is the best method for fetching data using jQuery to be used in a flot pie chart?

I am in the process of fetching data for a flot pie chart and want to ensure that I am doing it correctly. Any input would be greatly appreciated. I will also include the JSON data that is being returned so that I can confirm it adheres to the correct synt ...

Display or hide navigation item based on the success of a JavaScript post operation

Can I hide a nav-item in my navigation bar until I receive a response after submitting a form? The form sends data to an external API and upon successful submission, I want to display options on that specific nav-item. I can easily show the response but I ...

Performing a unique mysql query based on the selection made using onchange event in a select element while sending

I have an issue with executing a query onchange in a select element. The goal is to retrieve a specific price for a product based on the size selected. As a beginner with Ajax, I am struggling to send multiple data parameters. The first parameter should ...

Arrange in order by date followed by alphabetical sequence, ensuring that all active items are placed at the top in alphabetical order and all inactive items at the bottom in alphabetical order

https://i.sstatic.net/SgDDc.png I need to display a list sorted by signature date. If the signature date is not past-dated or missing, the record is considered active and should be sorted first alphabetically. Inactive records should come after active on ...

JQuery Mobile's Panel widget is the culprit behind the demise of the

I'm having some trouble adding a panel to my jQuery mobile page. Every time I try to input the code, all I see is a white screen with the loading widget, and nothing else happens. I have JQuery 2.0.0 hosted by Google, JQuery Mobile JS 1.3.1 hosted by ...

Customize the appearance of disabled dates in the eonasdan-datetimepicker styling

I am seeking to customize the default styles for the "eonasdan-datetimepicker" (https://github.com/Eonasdan/bootstrap-datetimepicker) by implementing a basic hover message feature. The CSS attributes currently applied to disabled dates are as follows: .bo ...

generate blob using file path vue electron packager

Currently, I am utilizing the fs module within my electron application to access file content from a specified path. ipcMain.on('fileData', (event, data) => { data.forEach( (file) => { const stream = fs.createReadStream(file) stream.o ...

Utilizing global variables from JavaScript in a React application

I'm facing an issue with a JS global variable in the index.html page that I need to access in my React JS app. I attempted to store the variable's value in local storage and then retrieve it in the React app. However, when I first tried to access ...