Attempted to execute a Vuex mutation outside of the designated store handler

Within my program, I have designed a form that consists of two checkboxes and a submit button for demonstration purposes. Upon clicking a checkbox, the selection is saved to a variable, which is then pushed to the vuex store when the submit button is clicked. This functionality works smoothly.

I have the flexibility to toggle the checkboxes on and off multiple times before finalizing my selections by hitting the submit button.

However, when I revisit the form and attempt to click on either checkbox, an error is triggered:

Error: [vuex] do not mutate vuex store state outside mutation handlers.
. This is the point where I have encountered a roadblock. My investigations into this issue have suggested that the problem lies in my use of v-model or the necessity to disable strict mode for vuex. I can confirm that I am not utilizing any v-models and prefer to maintain strict mode.

Below is a snippet of the form structure and submit button:

<v-expansion-panel class='panelButton'>
        <v-expansion-panel-header class='searchCardTitle'>Category of tool</v-expansion-panel-header>
        <v-expansion-panel-content>
          <v-checkbox dense hide-details=true v-for="tools in toolCategory" :key=tools :label=tools  @click="addMobileFilter(tools)" class="checkboxText"/>
        </v-expansion-panel-content>
      </v-expansion-panel>
     <v-expansion-panel class='panelButton'>
        <v-expansion-panel-header class='searchCardTitle'>Strategies</v-expansion-panel-header>
        <v-expansion-panel-content>
          <v-checkbox dense hide-details=true v-for="(tools,index) in toolStrategies" :key=tools :label=tools :value=toolStrategiesValues[index]  @click="addMobileFilter(toolStrategiesValues[index])" class="checkboxText"/>
        </v-expansion-panel-content>
<v-card-actions class="justify-center">
    <v-btn color="#699ad6" @click="updateMobileFilter()" class='white--text' style="margin 1rem 0 2rem 0">Apply</v-btn>
    </v-card-actions>

This excerpt does not cover the entirety of the file, but it encapsulates the key elements of my markup.

Here is the code snippet that is executed when a user interacts with a checkbox and subsequently clicks the submit button:

data() {
        return {
            tools: [],
            filteredTools:[],
            mobileFilters:[],
}
}
methods: {
        updateFilter: function(filter) {
            console.log(filter);
            this.$store.commit('populateFilterList',filter);
        },
        addMobileFilter: function(filter) {
            if(this.filteredTools.includes(filter)){
                const copy = this.filteredTools;
                const index = this.filteredTools.indexOf(filter);
                copy.splice(index, 1);
                this.filteredTools = copy;
            } else {
                this.filteredTools.push(filter);
            }
        },
        updateMobileFilter: function(){
            this.$store.commit('populateFilterList',this.filteredTools);
            this.$emit('dialogStatus',false);
        }
    }

Answer №1

My understanding is that the issue arises when you commit, as you're connecting filteredTools to your store and then changing it on this particular line:

this.filteredTools = copy;

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

Strangely odd actions from a JavaScript timepiece

After answering a question, I encountered a problem with my JavaScript clock that displays the day, time, and date on three lines. To make sure these lines have the same width, I used the BigText plugin, which works well except for one issue. tday=new A ...

Generating JSON on-the-fly with fluctuating keys and values in conjunction with Express JS

When I fetch an API into my Express server, the data comes in the form of JSON key-value pairs within an array. [{ "quality": "best", "url": "https://someurlhere.example/?someparameters" }, { "quality": ...

Encountering problems with displaying the index value in *ngFor directive in Angular 5

I am encountering a problem with rendering the index of *ngFor directive for a specific scenario as described below. Suppose we have an array of objects like this: this.temp = [ {name:'John',age:24,visibility:'visible'}, {name:&ap ...

Is there a way to duplicate items similar to MS Word by using a combination of ctrl + mouse click +

In my fabricjs application, I currently clone an object by clicking ctrl + left mouse click on it, which works fine. However, I would like to be able to clone the object in a similar way to MS WORD, by using ctrl + click + drag. Has anyone achieved this f ...

Ways to eliminate redundant older React components within a different library

Having trouble with material-ui in my React project as I encounter this error. Error: Invalid hook call. Ensure hooks are only called inside the body of a function component. Check for: Possible mismatch of React and renderer versions (i.e., React DOM) ...

Is there a way to incorporate cell highlighting on IE?

I've implemented a method to highlight selected cells based on the suggestion from jointjs. It surrounds the cell with a 2-pixel red border, which works well in Chrome. However, I need the outline to work in IE as well. Unfortunately, when I reviewed ...

Is there a way to exclusively submit form elements using Vue[2].js?

Currently, I have developed a form page that serves both creation and updating purposes. The structure of my form fields is as follows: myForm: { name: (...) email: (...) password: (...) } Successfully, I am able to make submission requests. Howev ...

Analyze two sets of JSON data and compile a new JSON containing only the shared values

I am trying to generate two JSON arrays based on a shared property value from comparing two sets of JSON data. this.linkedParticipants =[ { "id": 3, "name": "Participant 2", "email": "<a href="/ ...

Tips for transmitting an onChange function from a parent component to a child component in material UI

As a newcomer to react and material UI, I am currently working on developing a dropdown select component. My goal is to pass onChange functions to the component from its parent. Despite following the official documentation closely, I've encountered an ...

Changing the content of a form with a personalized message

I am currently working on a Feedback modal that includes a simple form with fields for Name, rating, and comment. After the user submits the form, I intend to display a custom message such as "Your feedback has been submitted." However, I am facing an issu ...

Tips for executing a function when the append-icon is clicked in Vuetify.js?

I am looking to implement the append-icon="close" feature that triggers @click="clearSearch()" Currently, I have it set up with a separate button: <v-text-field v-model="search" class="search" label=&quo ...

jquery survey quiz

Currently, I am attempting to develop a jQuery questionnaire, but my limited knowledge in the area is proving to be quite inadequate. So far, here is what I have: Upon clicking on "Questions," a pop-up window will appear with two questions. My goal is t ...

Unable to load the first tab in Material-ui V3 after fetching data or when the page loads

After using Material UI version 3 scrollable-tab and fetching data to load tabs and tab container, I encountered an issue where the first tab does not automatically load on page load. It requires a click in order to see the information. I have searched on ...

Is it possible to customize the MUI CSS for a specific menu item using the sx prop?

How can I apply the MenuItemStyle to the sx prop of a MenuItem using: const MenuItemStyle = { '&:hover': { backgroundColor: `${theme.color.secondaryHover}`, }, '&:selected, &:selected:hover': { backgroundColor: ...

Is there a way to access the history of Vue routers?

I am looking for a way to determine if the Vue router has additional entries in its history that can be navigated back to. This information is crucial for deciding whether or not to execute the exit app function. The app should only navigate back to prev ...

utilizing BrowserRouter for dynamic routing in react-router-dom

I'm currently facing a challenge with creating a multi-tenant SaaS solution. Each tenant needs to be able to use a subdomain, so that I can extract the subdomain from the URL and make a call to a REST API to retrieve data specific to that tenant. For ...

if a condition is not being properly assessed

Currently, I am working on a $.ajax call to retrieve data in JSON format. Within this JSON data, there is an element called "status." My code snippet checks if the value of `data.status` is equal to "success" and performs some actions accordingly. Despite ...

Refresh your HTML by reloading the JavaScript source

In my Ubuntu setup, I've been using chart.js to generate a graph displaying the values from a pressure sensor on an HTML document. Most of the project is complete, but I've encountered a challenge for which I haven't found a satisfactory sol ...

Introducing a pause in the function while rendering objects

After inserting setInterval into the code, it is causing all lasers to be delayed by one second. I am looking to have them fired in this order: - initially fire laser1 and laser2. - then take a 1-second break before firing another set of lasers, a ...

Utilize Laravel to trigger a route action based on a dropdown selection change, generating a unique URL

In my code, I have a dropdown select containing the list of the next 12 months: <select name="month" id="specificMonth"> @foreach(Carbon\CarbonPeriod::create(now()->startOfMonth(), '1 month', now()->addMon ...