Skip to content

Commit

Permalink
docs(zh): Update state.md about resetting the state (#2349) (#2359)
Browse files Browse the repository at this point in the history
Co-authored-by: edison <[email protected]>
  • Loading branch information
rich1e and edison1105 authored Oct 16, 2023
1 parent 3c79936 commit d3cbb3b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/docs/zh/core-concepts/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3cbb3b

Please sign in to comment.