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

222
Views
Unkonwn mutation type in vuex

I tried to mutate the state in vuex but, it always says vuex.esm-browser.js?5502:976 [vuex] unknown mutation type: addToCart. I called addToCart in mutation in two different ways as follows, but it is not working. It always throws the same error.

<button @click="addToCart(product)" class="add">Add</button>
import {mapMutations} from 'vuex'
    export default{
        methods:{
            ...mapMutations(["addToCart"]),
        },
        props: ["product"],
    }
</script>
Vuex store
import { createStore } from "vuex";

export default createStore({
    state:{
        cart: []
    },
    mutation:{
        addToCart(state, product){
            let item = state.cart.find(i=>i.id === product.id)

            if(item){
                item.quantity++
            }else{
                state.cart.push({...product, quantity: 1})
            }
        }
    }
})
I even tried this also
<button @click="addToCart()" class="add">Add</button>

<script>
   props: ["product"],
   methods:{
        addToCart(){
        this.$store.commit('addToCart', this.product)
     }
   }
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Shouldn't it be: mutations and not mutation in the store file?

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!