05笔记vuex mutation02

//App.vue

<template>
  <div id="app">
    {{ count }}<br/>
    <button @click="increment">+1</button><br/>
    <button @click="incrementBy(5)">+5</button><br/>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
  name: 'App',
  computed: mapState([
    'count'
  ]),
  // methods: {
  //   increment () {
  //     this.$store.commit('increment');
  //   },
  //   incrementBy () {
  //     this.$store.commit('incrementBy', 5);
  //   },
  //   decrement () {
  //     this.$store.commit('decrement', { amount: 1});
  //   },
  //   decrementBy () {
  //     this.$store.commit({ 
  //       type: 'decrementBy',
  //       amount: 5
  //     });
  //   }
  // }
  methods: mapMutations([
    'increment',
    'incrementBy'
  ])
}
</script>

发布了135 篇原创文章 · 获赞 67 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/qq_25479327/article/details/104200591
今日推荐