返回介绍

Interface: DefineStoreOptionsInPlugin

发布于 2024-04-14 00:17:41 字数 4698 浏览 0 评论 0 收藏 0

pinia.DefineStoreOptionsInPlugin

Available options when creating a pinia plugin.

Type parameters

NameType
Idextends string
Sextends StateTree
GG
AA

Hierarchy

Properties

actions

actions: A

Extracted object of actions. Added by useStore() when the store is built using the setup API, otherwise uses the one passed to defineStore(). Defaults to an empty object if no actions are defined.


getters

Optional getters: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties<string, StateTree, _GettersTree<StateTree>, _ActionsTree>> & _GettersTree<S>

Optional object of getters.

Inherited from

Omit.getters


state

Optional state: () => S

Type declaration

▸ (): S

Function to create a fresh state. Must be an arrow function to ensure correct typings!

Returns

S

Inherited from

Omit.state

Methods

hydrate

Optional hydrate(storeState, initialState): void

Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store definition and copying the value from pinia.state isn't enough.

Example

If in your state, you use any customRefs, any computeds, or any refs that have a different value on Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local storage:

ts
const useStore = defineStore('main', {
  state: () => ({
    n: useLocalStorage('key', 0)
  }),
  hydrate(storeState, initialState) {
    // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826
    storeState.n = useLocalStorage('key', 0)
  }
})

Parameters

NameTypeDescription
storeStateUnwrapRef<S>the current state in the store
initialStateUnwrapRef<S>initialState

Returns

void

Inherited from

Omit.hydrate

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文