Skip to content

Commit

Permalink
docs(zh): Update core-concepts/index.md (#2550)
Browse files Browse the repository at this point in the history
  • Loading branch information
zangbianxuegu committed Mar 4, 2024
1 parent 2a30fbc commit 11fa2ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/docs/zh/core-concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ const store = useCounterStore()

一旦 store 被实例化,你可以直接访问在 store 的 `state``getters``actions` 中定义的任何属性。我们将在后续章节继续了解这些细节,目前自动补全将帮助你使用相关属性。

请注意,`store` 是一个用 `reactive` 包装的对象,这意味着不需要在 getters 后面写 `.value`就像 `setup` 中的 `props` 一样,**如果你写了,我们也不能解构它**
请注意,`store` 是一个用 `reactive` 包装的对象,这意味着不需要在 getters 后面写 `.value`就像 `setup` 中的 `props` 一样,**我们不能对它进行解构**

```vue
<script setup>
import { useCounterStore } from '@/stores/counter'
const store = useCounterStore()
// ❌ 这将不起作用,因为它破坏了响应性
// 这就和直接解构 `props` 一样
Expand All @@ -136,6 +137,8 @@ const doubleValue = computed(() => store.doubleCount)
</script>
```

## 从 Store 解构

为了从 store 中提取属性时保持其响应性,你需要使用 `storeToRefs()`。它将为每一个响应式属性创建引用。当你只使用 store 的状态而不调用任何 action 时,它会非常有用。请注意,你可以直接从 store 中解构 action,因为它们也被绑定到 store 上:

```vue
Expand Down

0 comments on commit 11fa2ac

Please sign in to comment.