From: Rich1e Kung Date: Mon, 16 Oct 2023 09:52:31 +0000 (+0800) Subject: docs(zh): Update state.md about resetting the state (#2349) (#2359) X-Git-Tag: @pinia/nuxt@0.5.2-beta.0~126 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3cbb3ba274032403aa4aa99c71500472b042775;p=thirdparty%2Fvuejs%2Fpinia.git docs(zh): Update state.md about resetting the state (#2349) (#2359) Co-authored-by: edison --- diff --git a/packages/docs/zh/core-concepts/state.md b/packages/docs/zh/core-concepts/state.md index a6dbc227..43b1912d 100644 --- a/packages/docs/zh/core-concepts/state.md +++ b/packages/docs/zh/core-concepts/state.md @@ -93,6 +93,22 @@ const store = useStore() store.$reset() ``` +在 `$reset()` 内部,会调用 `state()` 函数来创建一个新的状态对象,并用它替换当前状态。 + +在 [Setup Stores](/core-concepts/index.md#setup-stores) 中,您需要创建自己的 `$reset()` 方法: + +```ts +export const useCounterStore = defineStore('counter', () => { + const count = ref(0) + + function $reset() { + count.value = 0 + } + + return { count, $reset } +}) +``` + ### 使用选项式 API 的用法 %{#usage-with-the-options-api}%