feat [front]: add store and manage loading
This commit is contained in:
parent
6cd090591b
commit
1ab6d112c0
5 changed files with 49 additions and 0 deletions
10
front/stores/README.md
Normal file
10
front/stores/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# STORE
|
||||
|
||||
**This directory is not required, you can delete it if you don't want to use it.**
|
||||
|
||||
This directory contains your Vuex Store files.
|
||||
Vuex Store option is implemented in the Nuxt.js framework.
|
||||
|
||||
Creating a file in this directory automatically activates the option in the framework.
|
||||
|
||||
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store).
|
21
front/stores/loadingStore.ts
Normal file
21
front/stores/loadingStore.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { defineStore } from "pinia"
|
||||
|
||||
export const useLoadingStore = defineStore("loading", {
|
||||
state: () => <{ [key: string]: "loading" | "done" | "error" }>{},
|
||||
actions: {
|
||||
markLoading(key: string) {
|
||||
this.$patch({ [key]: "loading" })
|
||||
},
|
||||
markDone(key: string) {
|
||||
this.$patch({ [key]: "done" })
|
||||
},
|
||||
markError(key: string) {
|
||||
this.$patch({ [key]: "error" })
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
isLoading: (state) => {
|
||||
return (key: string) => state[key] === "loading"
|
||||
},
|
||||
},
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue