vuex筆記03

// App.vue

<template>
  <div id="app">
    {{ count }}<br/>
    <button @click="increment">+</button><br/>
    {{ countAlias }} <br/>
    {{ countPlusLocalState }}
  </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
  name: 'App',
  // computed: {
  //   count () {
  //     return this.$store.state.count;
  //   }
  // },
  data() {
    return {
      localeCount: 4
    }
  },
  computed: mapState({
    count: state => state.count,
    countAlias: 'count',
    countPlusLocalState (state) {
      return state.count + this.localeCount;
    }
  }),
  methods: {
    increment () {
      // return this.$store.commit('increment');
      return this.$store.dispatch('increment');
    }
  }
}
</script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章