简体   繁体   English

错误:[vuex] 不要在变异处理程序之外改变 vuex 存储状态。 NUXT

[英]Error: [vuex] do not mutate vuex store state outside mutation handlers. NUXT

I'm using Nuxt and nuxt-vuex-localstorage When i change a item from v-for and it element is inside store i get an error...我正在使用 Nuxt 和 nuxt-vuex-localstorage 当我从 v-for 更改一个项目并且它的元素在商店内时,我收到一个错误...

<v-btn
              @click="addCurrentProduct( subItem)"
              v-if="!subItem.carrito"
              color="green"
              dark
              >Agregar</v-btn
            >
            <v-row v-if="subItem.carrito">
              <v-btn @click="subItem.cantidadCarrito--,removeProduct(subItem)" color="green" icon dark>
                <v-icon>mdi-minus-circle-outline</v-icon></v-btn
              >
              <span>{{
                subItem.cantidadCarrito
              }}</span>
              <v-btn @click="subItem.cantidadCarrito++,addProduct(subItem)" color="green" icon dark>
                <v-icon>mdi-plus-circle-outline</v-icon></v-btn
              >
            </v-row>

methods: {
    addCurrentProduct( product) {
      product.cantidadCarrito++;
      product.carrito = true;
      console.log("error")
      let temp=product
      this.$store.commit("localStorage/Sum_Cantidad");
      this.$store.commit("localStorage/ADD_PRODUCT", temp);


    },
addProduct(producto) {
      var temp = this.buscar(producto);   
      producto.carrito = true;   

      this.$store.commit("localStorage/ReNew_PRODUCTO", {
        index: temp,
        producto: producto
      });

      this.$store.commit("localStorage/Sum_Cantidad");
    }

I have error in subItem.cantidadCarrito++, i think that they are connected with Vuex store (Nuxt) and when i change it element, the element is inside of vuex also change and i get it error我在 subItem.cantidadCarrito++ 中有错误,我认为它们与 Vuex 商店(Nuxt)有关,当我更改它的元素时,元素在 vuex 内部也发生了变化,我得到它错误

我解决了这个问题,从localstorage 在vuex store 内部更改它,当我第一次放置一个项目时,这个元素会自动与localstorage 连接,我无法从本地外部进行任何更改。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM