错误代码

 

let store = new Vuex({
  state: {
    totalPrice: 0
  },
  mutations: {
    increment (state, price) {
      state.totalPrice += price
    },
    decrement (state, price) {
      state.totalPrice -= price
    }
  }
})

 

正确代码:

let store = new Vuex.Store({
  state: {
    totalPrice: 0
  },
  mutations: {
    increment (state, price) {
      state.totalPrice += price
    },
    decrement (state, price) {
      state.totalPrice -= price
    }
  }
})

 

 

分析:构造器写法写错了应该是new Vuex.Store({})

 

下面请忽略。。

 

 

let store = new Vuex({
state: {
totalPrice: 0
},
mutations: {
increment ( state, price) {
state. totalPrice += price
},
decrement ( state, price) {
state. totalPrice -= price
}
}
})

转载于:https://www.cnblogs.com/tabCtrlShift/p/9163498.html

Logo

前往低代码交流专区

更多推荐