]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: uniform variable syntax (#1787)
author國服第二切圖仔 <546967276@qq.com>
Wed, 9 Nov 2022 08:00:42 +0000 (16:00 +0800)
committerGitHub <noreply@github.com>
Wed, 9 Nov 2022 08:00:42 +0000 (09:00 +0100)
Co-authored-by: coffeemil <coffeemil@vip.qq.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
packages/docs/core-concepts/state.md
packages/docs/zh/core-concepts/state.md

index ded347f65f248cd9bba838613b37c8ccd2f9265a..92adef3bfdceb5edd11452cd35837cbcb685fc7b 100644 (file)
@@ -18,6 +18,8 @@ export const useStore = defineStore('storeId', {
       count: 0,
       name: 'Eduardo',
       isAdmin: true,
+      items: [],
+      hasChanged: true,
     }
   },
 })
@@ -184,7 +186,7 @@ store.$patch({
 However, some mutations are really hard or costly to apply with this syntax: any collection modification (e.g. pushing, removing, splicing an element from an array) requires you to create a new collection. Because of this, the `$patch` method also accepts a function to group this kind of mutations that are difficult to apply with a patch object:
 
 ```js
-cartStore.$patch((state) => {
+store.$patch((state) => {
   state.items.push({ name: 'shoes', quantity: 1 })
   state.hasChanged = true
 })
index 4967b394340352dac549c7e1097ba4c096281dfa..636a9e5cfa4152401b98e182438fb8fed7e6a900 100644 (file)
@@ -18,6 +18,8 @@ const useStore = defineStore('storeId', {
       count: 0,
       name: 'Eduardo',
       isAdmin: true,
+      items: [],
+      hasChanged: true,
     }
   },
 })
@@ -182,7 +184,7 @@ store.$patch({
 不过,用这种语法的话,有些变更真的很难实现或者很耗时:任何集合的修改(例如,从数组中推送、移除、拼接一个元素)都需要你创建一个新的集合。因此,`$patch` 方法也接受一个函数来组合这种难以用补丁对象实现的变更。
 
 ```js
-cartStore.$patch((state) => {
+store.$patch((state) => {
   state.items.push({ name: 'shoes', quantity: 1 })
   state.hasChanged = true
 })