index.js 548 B

1234567891011121314151617181920212223242526
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. export default new Vuex.Store({
  5. state: {
  6. totalUnread: 0 // 全局未读数(存储所有页面需要共享的值)
  7. },
  8. mutations: {
  9. // 更新未读数
  10. SET_TOTAL_UNREAD(state, count) {
  11. state.totalUnread = count
  12. }
  13. },
  14. actions: {
  15. // 触发更新未读数的动作
  16. updateTotalUnread({ commit }, count) {
  17. commit('SET_TOTAL_UNREAD', count)
  18. }
  19. },
  20. getters: {
  21. // 获取全局未读数
  22. getTotalUnread: state => state.totalUnread
  23. }
  24. })