当前位置: 首页 > news >正文

关于Vuex

Vuex

vuex在 数据结构相同,取值不同时,可以通过把数据格式载入vuex中转站,在需要数据请求时,引入vuex中转站的数据结构,同时把请求的参数赋值给它,从而完成数据请求.
由于vuex有单独的js文件,管理起来更加清晰和系统.

Vuex的拓展写法

tu1.png

此处为目录结构

import Vue from 'vue'
import Vuex from 'vuex'
import account from './account'
import taskManage from './taskManage'
import workReport from './workReport'
import msg from './msg'
import statistics from './statistics'
import createLoggger from 'vuex/dist/logger'
import resource from './resource'Vue.use(Vuex)
const debug = process.env.NODE_ENV !== 'production'
export default new Vuex.Store({modules: { account, taskManage, workReport, msg, statistics ,resource},strict: debug, // 开发环境下启用严格模式,plugins: debug ? [createLoggger()] : []
})

此处为store文件里的index.js根配置项

import state from './state';
import mutations from './mutations';
import * as getters from './getters';export default {namespaced: true,state,mutations,getters
};        

此处为statistics下的index.js配置项

// 筛选日期
export const SET_SEARCH_DATE = 'SET_SEARCH_DATE'
// 报修来源
export const SET_REPAIR_RESOURCE = 'SET_REPAIR_RESOURCE'

此处为statistics下的mutationTypes.js配置项

import * as types from './mutationTypes'
const mutations = {[types.SET_SEARCH_DATE](state, data) {state.dateInfo = data},[types.SET_REPAIR_RESOURCE](state, data) {state.repairResource = data}
}
export default mutations

此处为statistics下的mutations.js配置项

export const dateInfo = state => state.dateInfo
export const repairResource = state => state.repairResource

此处为statistics下的getters.js配置项

const state = {dateInfo: {curDate: null,showDate: ['', '']},repairResource: []
}
export default state

此处为statistics下的state.js配置项

 computed: {...mapGetters("statistics", ["dateInfo"])},
   ...mapMutations("statistics", {setSearchDate: "SET_SEARCH_DATE",setRepairResource: "SET_REPAIR_RESOURCE"})
   //调用 vux 里的 mapMutations  里的   setSearchDate  方法,传入对象  赋值给state里的dateInfoif (this.halfyearValue &&this.halfyearValue != null &&this.halfyearValue.length > 0) {this.setSearchDate({type,showDate,curDate:moment(this.halfyearValue[0]).date(1).format("X") * 1000,timeRange: [moment(this.halfyearValue[0]).startOf("months").valueOf(),moment(this.halfyearValue[1]).endOf("months").valueOf()]});}

引用vuex数据页面的 引用处

最后编辑于:2025-06-15 10:07:44


喜欢的朋友记得点赞、收藏、关注哦!!!

http://www.dtcms.com/a/288188.html

相关文章:

  • uhd_find_devices有serial但是GNU Radio显示find no devices
  • Vue rem回顾
  • YOLOv8中添加SENet注意力机制
  • XSS-Labs 各关卡测试过程
  • 统计学习方法
  • 如何解决 ext4 文件系统的元数据损坏问题
  • 【深度强化学习】MIP-DQN 实现案例(完整Python代码)
  • [spring6: IntroductionAdvisor IntroductionInterceptor]-源码分析
  • C++编程学习(第11天)
  • Patch-wise Structural:一种引入局部统计特性的时序预测损失函数
  • eNSP综合实验(DNCP、NAT、TELET、HTTP、DNS)
  • 定时器中BDTR死区时间和刹车功能配置
  • debian的pulseaudio删掉也没事
  • Go语言pprof性能分析指南
  • SIMATIC WinCC Unified 使用 KPI 优化流程
  • 永磁同步电机无速度算法--脉振正弦注入法
  • Kakfa集群部署及主题创建
  • haproxy七层代理
  • day7--绑定媒资、课程发布
  • kafka--基础知识点--6--AR、ISR、OSR
  • Mysql系列--3、数据类型
  • RTDETR融合DECS-Net中的FFM模块
  • Verilog *2* SPI-立创逻辑派G1测试-1
  • 多表查询-8-练习总结
  • 【LeetCode 热题 100】437. 路径总和 III——(解法一)递归递归!
  • 【Linux】mmap的介绍和使用
  • [硬件电路-36]:模拟电路的基本组成要素以及模拟信号处理
  • Python条件控制艺术:侦探破解犯罪谜题逻辑
  • 浏览器渲染原理——计算属性和布局过程常考内容
  • 如何实现一个定时任务