count.js 738 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //求和相关的配置
  2. export default {
  3. namespaced:true, //开启命名空间
  4. actions:{
  5. jiaOdd(context,value){
  6. console.log('actions中的jiaOdd被调用了')
  7. if(context.state.sum % 2){
  8. context.commit('JIA',value)
  9. }
  10. },
  11. jiaWait(context,value){
  12. console.log('actions中的jiaWait被调用了')
  13. setTimeout(()=>{
  14. context.commit('JIA',value)
  15. },500)
  16. }
  17. },
  18. mutations:{
  19. JIA(state,value){
  20. console.log('mutations中的JIA被调用了')
  21. state.sum += value
  22. },
  23. JIAN(state,value){
  24. console.log('mutations中的JIAN被调用了')
  25. state.sum -= value
  26. },
  27. },
  28. state:{
  29. sum:0, //当前的和
  30. school:'尚硅谷',
  31. subject:'前端',
  32. },
  33. getters:{
  34. bigSum(state){
  35. return state.sum*10
  36. }
  37. },
  38. }