一、目录结构: src -> js -> modules

1. 在modules下新建文件夹,文件夹名称按模块功能命名

如:

modules ———— home  -> homeModule.js
|
———— modal -> modalModule.js

2. 在modules 下新建stores.js,注册所有状态

import homeState from './homeModule.js'
import modalState from './modalModule.js' export const modules = {
modules: {
homeState,
modalState
}
}

3. 在入口文件,如main.js中引用 stores.js

import Vue from 'vue'
import Vuex from 'vuex'
import router from '@/js/router'
import { modules } from '@/js/modules/stores.js'
import HelloWorld from './HelloWorld' Vue.config.productionTip = false
Vue.use(Vuex) // 状态管理
const store = new Vuex.Store(modules); new Vue({
el: '#app',
router,
store,
components: { HelloWorld },
template: '<HelloWorld/>'
})

二、homeModule.js结构

export default module = {
state: {
count: 1
},
mutations: {
increment(state, componentData) {
// 变更状态
state.count = state.count + componentData
}
},
actions: {
// actions一般是处理异步逻辑
incrementData(context, componentData) {
context.commit('increment', componentData);
}
}
}

vuex-store模块化配置的更多相关文章

  1. Vue学习之--------深入理解Vuex之模块化编码(2022/9/4)

    在以下文章的基础上 1.深入理解Vuex.原理详解.实战应用:https://blog.csdn.net/weixin_43304253/article/details/126651368 2.深入理 ...

  2. Vuex的模块化、优点

    前言:如果说我们的vuex的仓库代码量巨大,我们要不要采用就像后端与一样的分层,要不然一吨的代码放在main里,呵呵.所以我们要采用模块化! 看这篇文章的时候,一定要看看上一篇的vuex入门精讲:Vu ...

  3. 074——VUE中vuex之模块化modules开发实例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Vue 路由模块化配置

    博客地址:https://ainyi.com/77 企业运营后台页面很多,路由如若不区分模块化配置,所有路由挤在同一个文件将不好维护,所以路由的配置也要模块化 分享两个解决方案 -- Vue 路由配置 ...

  5. vuex的模块化使用

    store文件如下 1.modules下文件是模块化的划分,里面的js有state,action,mutations.然后通过 export default { namespaced: true, s ...

  6. [Vuex] Split Vuex Store into Modules using TypeScript

    When the Vuex store grows, it can have many mutations, actions and getters, belonging to different c ...

  7. [Vuex] Create a Vuex Store using TypeScript

    A Vuex store centralizes the state of your app, making it easy to reason about your state flow. In t ...

  8. spring--多人开发,模块化配置

    需要在配置文件中配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...

  9. webpack快速入门——实战技巧:webpack模块化配置

    首先在根目录,新建一个webpack_config文件夹,然后新建entry_webpack.js文件,代码如下: const entry ={}; //声明entry变量 entry.path={ ...

  10. Do not mutate vuex store state outside mutation handlers.

    组件代码: selectItem(item,index) { this.selectPlay({ list: this.songs, index }) }, ...mapActions([ 'sele ...

随机推荐

  1. Windows改动cmd字符集

    在中文Windows系统中,假设一个文本文件是UTF-8编码的,那么在CMD.exe命令行窗体(所谓的DOS窗体)中不能正确显示文件里的内容.在默认情况下,命令行窗体中使用的代码页是中文或者美国的,即 ...

  2. hadoop集群中动态添加新的DataNode节点

    集群中现有的计算能力不足,须要另外加入新的节点时,使用例如以下方法就能动态添加新的节点: 1.在新的节点上安装hadoop程序,一定要控制好版本号,能够从集群上其它机器cp一份改动也行 2.把name ...

  3. HDOJ 4009 Transfer water 最小树形图

    Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) T ...

  4. Objective-C - NSInteger转换NSString

    NSInteger不是对象, 转换为long匹配64位系统, 再组成字符串(%ld). NSString *inStr = [NSString stringWithFormat: @"%ld ...

  5. poj--3281-- DiningI(最大流)

    Dining Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

  6. appid、appkey、appsecret、accesstoken,消息模板

    app_id, app_key, app_secret , 对于平台来说, 需要给你的 你的开发者账号分配对应的权限:1. app_id 是用来标记你的开发者账号的, 是你的用户id, 这个id 在数 ...

  7. 现实人脸识别性别之路----弄清楚train_test_split函数

    '''train_test_split(trian_data,trian_target,test_size,random_state)各个参数表示的意义:trian_data表示被划分的样本特征集tr ...

  8. U-BOOT启动流程分析--start.s(二)

    一.概述 u-boot的启动流程: 从文件层面上看主要流程是在两个文件中:cpu/arm920t/start.s,lib_arm/board.c, 先来分析start.s    在flash中执行的引 ...

  9. PHP获取一周后的时间戳

    echo strtotime("now");//相当于将英文单词now直接等于现在的日期和时间,并把这个日期时间转化为unix时间戳.这个效果跟echo time();一样. ec ...

  10. [Python] Reuse Code in Multiple Projects with Python Modules

    A module is a function extracted to a file. This allows you to import the function and use it in any ...