Browse Source

perf: `pinia`中所有`getters`改为官方推荐写法,`this`改成`state`可自动推导类型 (#490)

Co-authored-by: 苗大 <caoshengmiao@hypergryph.com>
Wit〆苗大 2 years ago
parent
commit
bff68c3e7b

+ 4 - 4
src/store/modules/app.ts

@@ -23,11 +23,11 @@ export const useAppStore = defineStore({
     sortSwap: false
   }),
   getters: {
-    getSidebarStatus() {
-      return this.sidebar.opened;
+    getSidebarStatus(state) {
+      return state.sidebar.opened;
     },
-    getDevice() {
-      return this.device;
+    getDevice(state) {
+      return state.device;
     }
   },
   actions: {

+ 5 - 5
src/store/modules/epTheme.ts

@@ -14,14 +14,14 @@ export const useEpThemeStore = defineStore({
       getConfig().Theme
   }),
   getters: {
-    getEpThemeColor() {
-      return this.epThemeColor;
+    getEpThemeColor(state) {
+      return state.epThemeColor;
     },
     /** 用于mix导航模式下hamburger-svg的fill属性 */
-    fill() {
-      if (this.epTheme === "light") {
+    fill(state) {
+      if (state.epTheme === "light") {
         return "#409eff";
-      } else if (this.epTheme === "yellow") {
+      } else if (state.epTheme === "yellow") {
         return "#d25f00";
       } else {
         return "#fff";

+ 2 - 2
src/store/modules/multiTags.ts

@@ -17,8 +17,8 @@ export const useMultiTagsStore = defineStore({
     )?.multiTagsCache
   }),
   getters: {
-    getMultiTagsCache() {
-      return this.multiTagsCache;
+    getMultiTagsCache(state) {
+      return state.multiTagsCache;
     }
   },
   actions: {

+ 6 - 6
src/store/modules/settings.ts

@@ -11,14 +11,14 @@ export const useSettingStore = defineStore({
     hiddenSideBar: getConfig().HiddenSideBar
   }),
   getters: {
-    getTitle() {
-      return this.title;
+    getTitle(state) {
+      return state.title;
     },
-    getFixedHeader() {
-      return this.fixedHeader;
+    getFixedHeader(state) {
+      return state.fixedHeader;
     },
-    getHiddenSideBar() {
-      return this.HiddenSideBar;
+    getHiddenSideBar(state) {
+      return state.hiddenSideBar;
     }
   },
   actions: {