简体   繁体   English

商店处理程序之外的错误 vuex 突变

[英]Error vuex mutation outside of store handler

In my program, I have a form.在我的程序中,我有一个表格。 This form has for this example two checkboxes, and a submit button.对于此示例,此表单有两个复选框和一个提交按钮。 When you click a checkbox it will save it to a variable, which gets pushed to my vuex store, when you click the button.当您单击一个复选框时,它会将其保存到一个变量中,当您单击该按钮时,该变量将被推送到我的 vuex 存储中。 This part works great.这部分效果很好。

I can also select and unselect the checkboxes as many times as I want, before I hit submit.在我点击提交之前,我也可以 select 并根据需要多次取消选中复选框。

However, if I go back to the form, and click either of the checkboxes, then it throws this error: Error: [vuex] do not mutate vuex store state outside mutation handlers.但是,如果我 go 返回表单,并单击其中一个复选框,则会抛出此错误: Error: [vuex] do not mutate vuex store state outside mutation handlers. . . And so that is where I am stuck.这就是我被困的地方。 I have looked at others who have asked the same question, and the general consensus is that either I am using a v-model or I have to take it out of strict mode for vuex.我看过其他人问过同样的问题,普遍的共识是要么我正在使用v-model ,要么我必须将它从 vuex 的严格模式中移除。 I do not have any v-models and I would like to leave it in strict mode.我没有任何v-models ,我想将其保留在严格模式下。

this is the form 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 is not the full file but has the relevant parts of my markup.这不是完整文件,但包含我标记的相关部分。

The following is the code, that is triggered when a user selects a checkbox and 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);
        }
    }

I think whats happening is that when commiting, you're binding filteredTools to your store, and then mutating it in this line:我认为发生的事情是,在提交时,你将 filteredTools 绑定到你的商店,然后在这一行中改变它:

this.filteredTools = copy;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue 错误消息:不要在变异处理程序之外改变 vuex 存储 - Vue Error Message: Do not mutate vuex store outside of mutation handler 为什么在变异处理程序内部变异“突变处理程序之外的Vuex存储状态”时会出错? - Why do I get an error for mutating “Vuex store state outside of mutation handlers” while inside a mutation handler? 错误:[vuex] 不要在突变处理程序 vuex (nuxt.js) 之外改变 vuex 存储 state - Error:[vuex] do not mutate vuex store state outside mutation handlers vuex (nuxt.js) Vuex 不会在突变处理程序之外改变 vuex 存储 state - Vuetify - Vuex do not mutate vuex store state outside mutation handlers - Vuetify Vuex 和 VueJS(不要在变异处理程序之外改变 vuex 存储状态) - Vuex & VueJS (Do not mutate vuex store state outside mutation handlers) nuxt vuex:不要在突变处理程序之外改变 vuex 存储 state - nuxt vuex: do not mutate vuex store state outside mutation handlers Vue Js-Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] do not mutate vuex store state outside mutation - Vue Js-Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] do not mutate vuex store state outside mutation “不要在突变处理程序之外改变 vuex 存储状态”错误,即使在为 prop 使用计算 var 之后也是如此 - "Do not mutate vuex store state outside mutation handlers" error even after using computed var for prop Vue 页面中的 Chart.js 抛出错误:不要在突变处理程序之外改变 vuex 存储 state - Chart.js in a Vue page throws error: do not mutate vuex store state outside mutation handlers 为什么会出现“不改变 vuex store state outside mutation handlers”的错误? - Why 'do not mutate vuex store state outside mutation handlers' error shows up?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM