Skip to content

Commit

Permalink
配置vuex
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jun 13, 2021
1 parent 8fa1af2 commit c7f42e7
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 2 deletions.
33 changes: 32 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
},
"dependencies": {
"element-plus": "^1.0.2-beta.46",
"es6-promise": "^4.2.8",
"vue": "^3.0.5",
"vue-router": "^4.0.8"
"vue-router": "^4.0.8",
"vuex": "^4.0.1"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.2.3",
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { createApp } from 'vue'
import ElementPlus from 'element-plus';
import 'element-plus/lib/theme-chalk/index.css';
import 'es6-promise/auto'
import Store from "./store"
import Router from "./router";
import App from './App.vue'

createApp(App)
.use(Store)
.use(Router)
.use(ElementPlus)
.mount('#app')
Expand Down
7 changes: 7 additions & 0 deletions src/store/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const actions = (r => {
return r.keys().map(key => r(key).actionTypes)
})(require.context('./module/', true, /^\.\/([\s\S])+\/index\.js$/))

const newActions = Object.assign({}, ...actions)

export default newActions
22 changes: 22 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createStore } from 'vuex'


const modules = (r => {
return r.keys().map(key => {
return {
name: key.match(/^\.\/([\s\S]+)\/index\.js$/)[1],
module: r(key).default
}
})
})(require.context('./module/', true, /^\.\/([\s\S])+\/index\.js$/))

let modulesObj = {}

modules.forEach(item => {
modulesObj[item.name] = item.module
})

export default createStore({
modules: modulesObj,
strict: process.env.NODE_ENV !== 'production'
})
33 changes: 33 additions & 0 deletions src/store/module/user/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import storage from '@/config/storage'

const actionTypes = {}

const mutationTypes = {}

const state = ()=>{
return {
user: null,
}
}

const getters = {

}

const actions = {}

const mutations = {

}

export {
actionTypes,
mutationTypes
}

export default {
state,
getters,
actions,
mutations
}
7 changes: 7 additions & 0 deletions src/store/mutation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const mutations = (r => {
return r.keys().map(key => r(key).mutationTypes)
})(require.context('./module/', true, /^\.\/([\s\S])+\/index\.js$/))

const newMutations = Object.assign({}, ...mutations)

export default newMutations

0 comments on commit c7f42e7

Please sign in to comment.