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 ...
随机推荐
- rac_grid自检提示缺少pdksh-5.2包
原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...
- poj1062 Bellman 最短路应用
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41066 Accepted: 11959 Descripti ...
- style="background-image: url(__HOMEPAGE__/views/IMJ2V2/images/banner2.jpg)"
style="background-image: url(__HOMEPAGE__/views/IMJ2V2/images/banner2.jpg)" 一.问题 backgroun ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 (B,F,L,M)
B. Train Seats Reservation You are given a list of train stations, say from the station 1 to the sta ...
- 原生js模拟jquery中的addClass和removeClass方法
js代码: //添加类 function addClass(obj,className) { if(obj.className == '') { //如果没有class obj.className = ...
- 51nod 最大子矩阵和
一个M*N的矩阵,找到此矩阵的一个子矩阵,并且这个子矩阵的元素的和是最大的,输出这个最大的值. 我们可以降维,枚举矩形的长,然后算出一个一维数组,然后就转化成了最大字段和问题 #include< ...
- Swift学习笔记(10)--枚举
1.定义语法: enum SomeEnumeration { // enumeration definition goes here } 2.使用 enum CompassPoint { case N ...
- 【Henu ACM Round#15 A】 A and B and Chess
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计大写和小写的个数. 比较答案.输出即可. [代码] #include <bits/stdc++.h> using n ...
- 【TC SRM 718 DIV 2 B】Reconstruct Graph
[Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...
- 洛谷 P3585 [POI2015]PIE
P3585 [POI2015]PIE 题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色.你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上 ...