Skip to content
Shimon's BlogShimon's Blog
主页
杂谈
  • 主页
      • 代码笔记
          • Vue.js
            • TypeScript 组件 Demo
              • Vue 与小程序的异同
                • Vue 单文件组件说明
                    • Vuex
                      • 快速上手
                        • 模块案例
                          • Sreen.ts
                        • 在 Vue 中使用 Typescript
                          • 开发环境安装
                            • 快速上手 Vue.js
                              • 组件使用说明

                            模块案例

                            Shimon Zhan2022年4月19日
                            • Vue
                            • Vuex
                            • Demo
                            小于 1 分钟

                            此页内容
                            • Sreen.ts

                            本案例展示了 Shimon Zhan 个人编写的 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;
                            

                            本文件包含了完整的一份 state、数个 mutation 和一个 action。

                            上次编辑于: 2022/4/19 07:13:07
                            贡献者: ShimonZhan
                            上一页
                            快速上手
                            Copyright © 2021-present Shimon Zhan