From: 國服第二切圖仔 <546967276@qq.com> Date: Wed, 9 Nov 2022 08:00:42 +0000 (+0800) Subject: docs: uniform variable syntax (#1787) X-Git-Tag: @pinia/nuxt@0.4.4~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f4caedbe3a0c07c9f9afcae604b36a17e903b74;p=thirdparty%2Fvuejs%2Fpinia.git docs: uniform variable syntax (#1787) Co-authored-by: coffeemil Co-authored-by: Eduardo San Martin Morote --- diff --git a/packages/docs/core-concepts/state.md b/packages/docs/core-concepts/state.md index ded347f6..92adef3b 100644 --- a/packages/docs/core-concepts/state.md +++ b/packages/docs/core-concepts/state.md @@ -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 }) diff --git a/packages/docs/zh/core-concepts/state.md b/packages/docs/zh/core-concepts/state.md index 4967b394..636a9e5c 100644 --- a/packages/docs/zh/core-concepts/state.md +++ b/packages/docs/zh/core-concepts/state.md @@ -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 })