From 6f4caedbe3a0c07c9f9afcae604b36a17e903b74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=9C=8B=E6=9C=8D=E7=AC=AC=E4=BA=8C=E5=88=87=E5=9C=96?= =?utf8?q?=E4=BB=94?= <546967276@qq.com> Date: Wed, 9 Nov 2022 16:00:42 +0800 Subject: [PATCH] docs: uniform variable syntax (#1787) Co-authored-by: coffeemil Co-authored-by: Eduardo San Martin Morote --- packages/docs/core-concepts/state.md | 4 +++- packages/docs/zh/core-concepts/state.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 }) -- 2.47.3