import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Store({ state: { totalUnread: 0 // 全局未读数(存储所有页面需要共享的值) }, mutations: { // 更新未读数 SET_TOTAL_UNREAD(state, count) { state.totalUnread = count } }, actions: { // 触发更新未读数的动作 updateTotalUnread({ commit }, count) { commit('SET_TOTAL_UNREAD', count) } }, getters: { // 获取全局未读数 getTotalUnread: state => state.totalUnread } })