index.js 505 B

12345678910111213141516171819202122
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const store = new Vuex.Store({
  5. state: {
  6. //公共的变量,这里的变量不能随便修改,只能通过触发mutations的方法才能改变
  7. quantity:0
  8. },
  9. mutations: {
  10. //相当于同步的操作
  11. changeQuan(state,data){
  12. state.quantity = state.quantity + data
  13. }
  14. },
  15. actions: {
  16. //相当于异步的操作,不能直接改变state的值,只能通过触发mutations的方法才能改变
  17. }
  18. })
  19. export default store