vuex-store模块化配置
一、目录结构: 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模块化配置的更多相关文章
- Vue学习之--------深入理解Vuex之模块化编码(2022/9/4)
在以下文章的基础上 1.深入理解Vuex.原理详解.实战应用:https://blog.csdn.net/weixin_43304253/article/details/126651368 2.深入理 ...
- Vuex的模块化、优点
前言:如果说我们的vuex的仓库代码量巨大,我们要不要采用就像后端与一样的分层,要不然一吨的代码放在main里,呵呵.所以我们要采用模块化! 看这篇文章的时候,一定要看看上一篇的vuex入门精讲:Vu ...
- 074——VUE中vuex之模块化modules开发实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Vue 路由模块化配置
博客地址:https://ainyi.com/77 企业运营后台页面很多,路由如若不区分模块化配置,所有路由挤在同一个文件将不好维护,所以路由的配置也要模块化 分享两个解决方案 -- Vue 路由配置 ...
- vuex的模块化使用
store文件如下 1.modules下文件是模块化的划分,里面的js有state,action,mutations.然后通过 export default { namespaced: true, s ...
- [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 ...
- [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 ...
- spring--多人开发,模块化配置
需要在配置文件中配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...
- webpack快速入门——实战技巧:webpack模块化配置
首先在根目录,新建一个webpack_config文件夹,然后新建entry_webpack.js文件,代码如下: const entry ={}; //声明entry变量 entry.path={ ...
- Do not mutate vuex store state outside mutation handlers.
组件代码: selectItem(item,index) { this.selectPlay({ list: this.songs, index }) }, ...mapActions([ 'sele ...
随机推荐
- 24. 在IDEA中使用JUnit进行方法测试
转自:https://blog.csdn.net/smxjant/article/details/78206279 1. 前文 刚学习到的新技能,对JUnit的了解也还是皮毛程度,在这里做个笔记.如果 ...
- Asp.Net碎知识
在aspx页面 获取值: UserModel user=new UserModel();实例化 user.Address=context["txtAddress"]; 如果前台不需 ...
- c#记录日志的方法
/// <summary> /// 生成日志 /// </summary> /// <param name="text"></param& ...
- cf 864 F. Cities Excursions
F. Cities Excursions There are n cities in Berland. Some pairs of them are connected with m directed ...
- JS 引擎基础之 Shapes and Inline Caches
阅读下面这篇文章,需要20分钟: 一起了解下 JS 引擎是如何运作的吧! JS 的运作机制可以分为 AST 分析.引擎执行两个步骤: JS 源码通过 parser(分析器)转化为 AST(抽象语法树) ...
- 51nod 编辑距离 + 滚动数组优化
这道题一开始觉得增加和删除会移动字符串的位置很不好做 两个字符串dp状态一般是第一个前i个和第二个前j个 #include<cstdio> #include<algorithm> ...
- SFML学习纪要
工作需要,近段粗浅看了一下SFML,记录一下! 一.浅见概述 SFML,simple and Fast mulitmedia Library官方网站:http://www.sfml-dev.org/i ...
- 【Uva 10723】Cyborg Genes
[Link]: [Description] 给你两个串s1,s2; 让你生成一个串S; 使得s1和s2都是S的子列; 要求S最短; 求S的不同方案个数; [Solution] 设两个串的长度分别为n1 ...
- Activiti工作流框架学习(二)——使用Activiti提供的API完成流程操作
可以在项目中加入log4j,将logj4.properties文件拷入到src目录下,这样框架执行的sql就可以输出到到控制台,log4j提供的日志级别有以下几种: Fatal error war ...
- 学一下gconv, gprof等知识
scons.gcc.gdb.valgrind.gcov SCons 是一个用 Python 语言编写的类似于 make 工具的程序.与 make 工具相比较,SCons 的配置文件更加简单清晰明了. ...