]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs(zh): Update state.md about resetting the state (#2349) (#2359)
authorRich1e Kung <yuqigong@outlook.com>
Mon, 16 Oct 2023 09:52:31 +0000 (17:52 +0800)
committerGitHub <noreply@github.com>
Mon, 16 Oct 2023 09:52:31 +0000 (11:52 +0200)
Co-authored-by: edison <daiwei521@126.com>
packages/docs/zh/core-concepts/state.md

index a6dbc227c03379effcd66c953770b3875c34ae38..43b1912da27cc4aa2f3d95733fc569ee65b7916a 100644 (file)
@@ -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}%
 
 <VueSchoolLink