-
Notifications
You must be signed in to change notification settings - Fork 1
/
store.ts
93 lines (90 loc) · 2.03 KB
/
store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { EnhanceStore } from '../src/store';
import Vuex from 'vuex';
import Vue from 'vue';
Vue.use(Vuex);
const state = {
state: {
name: 'this is name',
},
actions: {
setName({ commit }, payload?: string) {
commit('setName', payload);
return 1
},
setName2({ commit }, test?: string) {
commit('setName');
return 1
},
},
mutations: {
setName(state, payload) {
state.name = payload;
},
},
getters: {
getName(state) {
return state.name as string;
},
getName2(state) {
return state.name as string;
},
},
modules: {
user: {
namespaced: true,
state: {
username: 'this is username',
meta: {
age: 20,
address: 'address'
}
},
actions: {
updateUsername({ commit }, payload: string) {
commit('setUsername', payload);
},
updateUserMeta({ commit }, payload: { age?: number; address?: string }) {
commit('setUsername', payload);
},
noParam({ commit }) {
commit('setUsername');
},
test: {
root: true,
handler({ commit }, payload: number) { return 2; }
}
},
mutations: {
setUsername(state, payload) {
state.username = payload
},
setUserMeta(state, payload: { age?: number; address?: string }) {
state.meta = {
...state.meta,
...payload
};
}
},
getters: {
getUsername(state) {
return state.username as string
},
getUsername2(state) {
return state.username as string
}
}
},
},
};
const s = new EnhanceStore(state);
export const { mapGetters, store, mapActions, mapMutations, mapState, dispatch } = s;
mapActions('user', ['test']).test
dispatch('setName2')
var aa = dispatch('setName')('ds')
dispatch('user','test')
dispatch('user', 'updateUserMeta')({
address: '',
age: 1
})
dispatch('user', 'test')(1)
dispatch('setName')('1')