From 9860e221460a0a4ac1903dad2c97160d0eed0e63 Mon Sep 17 00:00:00 2001 From: long <515897141@qq.com> Date: 星期五, 03 三月 2023 10:59:42 +0800 Subject: [PATCH] 初始化 --- src/store/index.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..0bebcdb --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,59 @@ +/* + * @Author: 涓橀獜_jun + * @Date: 2019-11-21 10:59:17 + * @Last Modified by: 涓橀獜_jun + * @Last Modified time: 2021-05-14 18:28:18 + */ +import Vue from 'vue' +import Vuex from 'vuex' +// import fn from '../utils/fn.js' +Vue.use(Vuex) + +const state = {} + + +// 鏄惧紡鏇存敼state锛屽唴閮ㄥ彧鍏佽鍚屾锛岃皟鐢ㄦ柟寮忥細$store.commit(key, value) +const mutations = {} + +// 鐩稿綋浜巆omputed锛岃皟鐢ㄦ柟寮忥細store.getters.xxx +const getters = {} + +// 鍏佽寮傛锛岄渶閫氳繃store.dispath鍒嗗彂锛岃皟鐢╯tore.commit鏇存敼state +const actions = {} + +/** + * 棣栧瓧姣嶅彉澶у啓 + * @param {string} name + */ +function getBigName(name){ + return [name[0].toUpperCase(), ...name.substring(1)].join('') +} + +/** + * 浣跨敤create锛屽揩鎹峰垱寤虹畝鏄撳瓧娈� + * 閫氱敤鍒涘缓store瀛楁锛屽寘鍚玸tate,getters,mutations + * @param {string} key + * @param {*} default_value + * @param {function} mutation + */ +function create (key, default_value, mutation) { + state[key] = default_value + mutations['set' + getBigName(key)] = mutation || ((state, value) => {state[key] = value}) + getters['get' + getBigName(key)] = state => state[key] +} + +// 鐢ㄦ埛淇℃伅 +create('userData', {}) +// danmuData: [], // 寮瑰箷鏁版嵁 +// luckNum: 0, // 骞歌繍鍊兼暟鎹� +// shareNum: 0, // 鍒嗕韩娆℃暟 +// leftNum: 0, // 鍓╀綑鎶藉娆℃暟 + +const store = new Vuex.Store({ + state, + getters, + mutations, + actions, +}) + +export default store -- Gitblit v1.8.0