]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs(zh): update composing-stores.md (#2094)
authorlion414 <84086945+lion414@users.noreply.github.com>
Sat, 8 Apr 2023 11:55:08 +0000 (19:55 +0800)
committerGitHub <noreply@github.com>
Sat, 8 Apr 2023 11:55:08 +0000 (13:55 +0200)
packages/docs/cookbook/composing-stores.md
packages/docs/zh/cookbook/composing-stores.md
packages/docs/zh/core-concepts/actions.md
packages/docs/zh/core-concepts/index.md
packages/docs/zh/core-concepts/outside-component-usage.md
packages/docs/zh/core-concepts/plugins.md
packages/docs/zh/core-concepts/state.md

index fd3e7eca291a0dc3ad902f5390d79296318e9ff6..c745f36d11661044ac7d49d59bb46ff3d7448cef 100644 (file)
@@ -51,9 +51,10 @@ import { useUserStore } from './user'
 
 export const useCartStore = defineStore('cart', () => {
   const user = useUserStore()
+  const list = ref([])
 
   const summary = computed(() => {
-    return `Hi ${user.name}, you have ${state.list.length} items in your cart. It costs ${state.price}.`
+    return `Hi ${user.name}, you have ${list.value.length} items in your cart. It costs ${price.value}.`
   })
 
   function purchase() {
index c051c8110fdb4aa021e05ebbde037b365268b421..9b8a8def906c2119f60a351fa98a7bc891025dfc 100644 (file)
@@ -51,9 +51,10 @@ import { useUserStore } from './user'
 
 export const useCartStore = defineStore('cart', () => {
   const user = useUserStore()
+  const list = ref([])
 
   const summary = computed(() => {
-    return `Hi ${user.name}, you have ${state.list.length} items in your cart. It costs ${state.price}.`
+    return `Hi ${user.name}, you have ${list.value.length} items in your cart. It costs ${price.value}.`
   })
 
   function purchase() {
index e521dd644cbcc45585ee92070246d27fbf88fa6e..220f5f553f2f5eea08ec09f550a697be5104499d 100644 (file)
@@ -208,7 +208,7 @@ unsubscribe()
 ```vue
 <script setup>
 const someStore = useSomeStore()
-// 该订阅器将被保留,即使组件被卸载
+// 此订阅器即便在组件卸载之后仍会被保留
 someStore.$onAction(callback, true)
 </script>
 ```
index 52907709c423e7bc927c5ec04db4fff9dd47b342..1e5340e7bbf8f7965db8ccd994f90f79acad55f5 100644 (file)
@@ -77,7 +77,7 @@ Setup store 比 [Option Store](#option-stores) 带来了更多的灵活性,因
 ```vue
 <script setup>
 import { useCounterStore } from '@/stores/counter'
-// å\9c¨ç»\84ä»¶ç\9a\84ä»»ä½\95å\9c°æ\96¹访问 `store` 变量 ✨
+// å\8f¯ä»¥å\9c¨ç»\84件中ç\9a\84ä»»æ\84\8fä½\8dç½®访问 `store` 变量 ✨
 const store = useCounterStore()
 </script>
 ```
@@ -93,8 +93,8 @@ const store = useCounterStore()
 ```vue
 <script setup>
 const store = useCounterStore()
-// ❌ 这样是不可行的,因为它会破坏响应性
-// 就与直接解构 `props` 一样
+// ❌ 这将不起作用,因为它破坏了响应性
+// 这就和直接解构 `props` 一样
 const { name, doubleCount } = store // [!code warning]
 name // 将始终是 "Eduardo" // [!code warning]
 doubleCount // 将始终是 0 // [!code warning]
@@ -113,9 +113,9 @@ const doubleValue = computed(() => store.doubleCount)
 <script setup>
 import { storeToRefs } from 'pinia'
 const store = useCounterStore()
-// `name` 和 `doubleCount` 是响应式的 ref
-// 这也会提取插件添加的 ref 属性
-// 但会跳过任何 action 或非响应式(非 ref/reactive)属性
+// `name` 和 `doubleCount` 是响应式的 ref
+// 同时通过插件添加的属性也会被提取为 ref
+// 并且会跳过所有的 action 或非响应式 (不是 ref 或 reactive) 的属性
 const { name, doubleCount } = storeToRefs(store)
 // 作为 action 的 increment 可以直接解构
 const { increment } = store
index a4adaaa303aefb45484c3355ebe8157b85e66aa5..bd5f6416c9e4f26b45035419a97a8c16f6ad8b5b 100644 (file)
@@ -39,14 +39,14 @@ const router = createRouter({
 const store = useStore()
 
 router.beforeEach((to, from, next) => {
-  // 我们想用这里的 store
+  // 我们想要在这里使用 store
   if (store.isLoggedIn) next()
   else next('/login')
 })
 
 router.beforeEach((to) => {
-  // ✅ 这样做是可行的,因为路由器在安装完之后就会开始导航。
-  // Pinia 也将被安装。
+  // ✅ 这样做是可行的,因为路由器是在其被安装之后开始导航的,
+  // 而此时 Pinia 也已经被安装。
   const store = useStore()
 
   if (to.meta.requiresAuth && !store.isLoggedIn) return '/login'
index 80972f00b993d818c707dde7a37ff388ba2e6129..eeeccfd162520b1bf1d5d38b61254a8088a3ca88 100644 (file)
@@ -104,7 +104,7 @@ pinia.use(({ store }) => {
 
 ### 添加新的 state %{#adding-new-state}%
 
-如果你想给 store 添加新的 state 属性,或者在激活过程中使用的属性,**你必须同时在两个地方添加它**
+如果你想给 store 添加新的 state 属性或者在服务端渲染的激活过程中使用的属性,**你必须同时在两个地方添加它**。
 
 - 在 `store` 上,然后你才可以用 `store.myState` 访问它。
 - 在 `store.$state` 上,然后你才可以在 devtools 中使用它,并且,**在 SSR 时被正确序列化(serialized)**。
index 72613effbce75b7e00fa084d60b8f9784bc2e214..bbb62d63354a6d47a905cd3cca78ea435342c237 100644 (file)
@@ -234,7 +234,7 @@ cartStore.$subscribe((mutation, state) => {
 ```vue
 <script setup>
 const someStore = useSomeStore()
-// 该订阅器将被保留,即使组件被卸载
+// 此订阅器即便在组件卸载之后仍会被保留
 someStore.$subscribe(callback, { detached: true })
 </script>
 ```