一、目录结构: 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. Java中发送http的get、post请求

    近期做项目中,须要把消息通过中间件的形式通过http请求的方式推送给第三方,因此用到了http协议,小编花费了一个多小时.对于http协议中的post和get请求,封装了一个工具类.以下与大家分享一下 ...

  2. 3.React Native在Android中自己定义Component和Module

    React Native终于展示的UI全是Native的UI.将Native的信息封装成React方便的调用. 那么Native是怎样封装成React调用的?Native和React是怎样交互的? V ...

  3. IOS &#39;NSInternalInconsistencyException&#39;

    今天想写一个请求的天气.好的.废话不多说.先贴代码: 使用AFNetWorking 发送get请求,可是一直报错  IOS 'NSInternalInconsistencyException', re ...

  4. ISheet ICell

    /// <summary> /// Gets the first row on the sheet /// </summary> /// <value>the nu ...

  5. poj--1488--TEX Quotes(水题)

    TEX Quotes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9672   Accepted: 5071 Descri ...

  6. Gym - 100203G Good elements 水+模拟

    题意:good element的定义是a[i]在1~i-1中任取三个数(可以重复)的和能等于a[i] 思路:vis[x]标记一下任两个数的和,处理a[i]时枚举1~i-1判断vis[a[i] - a[ ...

  7. 用JS把复选框做成单选框,左显示div,右隐藏div

    <input type="checkbox" name="checkname" onclick="check(this)"/>左 ...

  8. 学习总结--Dom

    节点(每个元素都会有的3个nodeValue nodeType nodeName:) 1 元素节点 nodeName 元素节点名 nodeType 1 nodeValue null或者undefine ...

  9. window安装MQTT服务器和client

    http://activemq.apache.org/apollo/download.html  官方下载地址   MQTT目录: MQTT简单介绍 window安装MQTT服务器和client ja ...

  10. 关于props default 数组/对象的默认值应当由一个工厂函数返回

    export default {props: { xAxisData: {   type: Array,   default: [] }, },这是我的代码 报错是Invalid default va ...