模块案例
Mr.Hope ... 小于 1 分钟
本案例展示了 Mr.Hope 个人编写的 screen 相关的 Vuex 模块。
# Sreen.ts
import { Module } from "vuex";
import { BaseState } from "../state";
export interface SWState {
status: string; // service-worker 状态
error?: Error;
}
const swState: SWState = { status: "" };
const swModule: Module<SWState, BaseState> = {
state: swState,
mutations: {
/**
* @description: 设置 Service Worker 状态
*
* @param state swState
* @param status ServiceWorker状态
*/
swState(state: SWState, status: string): void {
state.status = status;
},
/**
* @description: 设置 Service Worker 错误
*
* @param state imagestate
* @param error 遇到的错误
*/
swError(state: SWState, error: Error): void {
state.status = "error";
state.error = error;
},
},
};
export default swModule;
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
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
本文件包含了完整的一份 state、数个 mutation 和一个 action。