其他分享
首页 > 其他分享> > vuex modules

vuex modules

作者:互联网

store/index.js

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const moduleA = {
  state: () => ({
    count: 0
  }),
  mutations: {
    increment (state) {
      state.count++
    }
  },
  getters: {
    doubleCount (state) {
      return state.count * 2
    }
  }
}
const store = new Vuex.Store({
  modules: {
    moduleA
  }
})
export default store
<template>
  <div>
    {{ moduleA }}
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState({
      moduleA: (state) => state.moduleA.count,
    }),
  },
};
</script>

标签:count,Vuex,modules,state,store,import,vuex,moduleA
来源: https://blog.csdn.net/weixin_40030173/article/details/112833258