import Vue from 'vue' import Vuex from 'vuex' import { mutations } from './mutations' import { actions } from './actions' import { initBaseState } from './state' import chat from './module/chat' import group from './module/group/index' Vue.use(Vuex) const state = initBaseState() const getters = { // 判断是否是私聊 isPrivate: state => { return /-/g.test(state.curSession) }, // 私聊时候对方的userId otherUserId: state => { if (!state.curSession) return if (state.curSession.indexOf('-') > -1) { return state.curSession.replace('-', '').replace(state.userId, '') } else { return '' } } } export default new Vuex.Store({ state, mutations, actions, getters, modules: { chat, group } })