🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ### 标准结构 ![](https://box.kancloud.cn/47dbfd3da4ae7ca3d96df2d0cd74e2d2_177x156.png) * [ ] state 保存数据 * [ ] mutations 改变state数据 * [ ] actions 调用 mutaions * [ ] module 模块 * [ ] user.js 模块中的状态数据管理 ***** index.js ``` import Vue from 'vue' import Vuex from 'vuex' import state from './state' import actions from './actions' import mutations from './mutations' import user from './module/user' Vue.use(Vuex) export default new Vuex.Store({ state, mutations, actions, modules: { user } }) ``` ***** state.js ``` const state = { // state 用于存放数据 } export default state ``` ***** mutations.js ``` const mutations = { // 改变 state 数据 } export default mutations ``` ***** actions.js ``` const actions = { // 改变 mutations } export default actions ``` ***** module / user.js ``` const state = { userName: '胖妞' } const actions = {} const mutations = {} export default { namespaced: true, state, actions, mutations } ```