@@ -11,6 +11,7 @@ type CommitNameType = AppStateType & ConsoleStateType & UserStateType
11
11
12
12
/**
13
13
* @description setStoreState -方法是一个 mutaitions 的操作
14
+ * @type {T } T - 你要更改的模块的类型
14
15
* @param {string } module - 要操作的state 的 module 名
15
16
* @param {string } key - 要操作的state 的 module 下的 key 值
16
17
* @param {any } value - 当有 msg 参数时,视为赋值操作,触发 mutation,msg 则为要复制的数据.
@@ -24,17 +25,39 @@ type CommitNameType = AppStateType & ConsoleStateType & UserStateType
24
25
* }
25
26
* }
26
27
* ```
27
- * 想要单独修改 firstName,直接使用 setStoreState('app','name',{firstName:'modifiedName',lastName:'Ma'})
28
+ * 想要单独修改 firstName,直接使用 setStoreState<AppStateType> ('app','name',{firstName:'modifiedName',lastName:'Ma'})
28
29
*/
29
30
30
- export const setStoreState = (
31
+ export function setStoreState < T > (
31
32
module : ModuleNameType ,
32
- key : keyof CommitNameType ,
33
+ key : keyof T ,
33
34
value : any
34
- ) => {
35
+ ) {
35
36
store . commit ( {
36
37
type : module + '/__set' ,
37
38
key : key ,
38
39
val : value
39
40
} )
40
41
}
42
+
43
+ /**
44
+ * @description 封装 dispatch 方法
45
+ * @type {T } T 你要派发actions的模块的类型
46
+ * @example 使用方法如下 const result = await dispatchActions<UserActionsType>('console','refreshToken',1)
47
+ */
48
+ export function dispatchAction < T > (
49
+ module : ModuleNameType ,
50
+ key : keyof T ,
51
+ value ?: any
52
+ ) {
53
+ store . dispatch ( `${ module } /${ key } ` , value )
54
+ }
55
+
56
+ /**
57
+ * @description 封装 dispatch 方法
58
+ * @type {T } T 你要获取 getters的模块的类型
59
+ * @example 使用方法如下 const result = getStoreGetter<ConsoleGetterType>('console','list')
60
+ */
61
+ export function getStoreGetter < T > ( module : ModuleNameType , key : keyof T ) {
62
+ store . getters [ `${ module } /${ key } ` ]
63
+ }
0 commit comments