Count.vue 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div>
  3. <h1>当前求和为:{{$store.state.sum}}</h1>
  4. <select v-model.number="n">
  5. <option value="1">1</option>
  6. <option value="2">2</option>
  7. <option value="3">3</option>
  8. </select>
  9. <button @click="increment">+</button>
  10. <button @click="decrement">-</button>
  11. <button @click="incrementOdd">当前求和为奇数再加</button>
  12. <button @click="incrementWait">等一等再加</button>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name:'Count',
  18. data() {
  19. return {
  20. n:1, //用户选择的数字
  21. }
  22. },
  23. methods: {
  24. increment(){
  25. this.$store.commit('JIA',this.n)
  26. },
  27. decrement(){
  28. this.$store.commit('JIAN',this.n)
  29. },
  30. incrementOdd(){
  31. this.$store.dispatch('jiaOdd',this.n)
  32. },
  33. incrementWait(){
  34. this.$store.dispatch('jiaWait',this.n)
  35. },
  36. },
  37. mounted() {
  38. console.log('Count',this)
  39. },
  40. }
  41. </script>
  42. <style lang="css">
  43. button{
  44. margin-left: 5px;
  45. }
  46. </style>