From: coyotte508 Date: Sun, 12 Sep 2021 10:51:00 +0000 (+0200) Subject: docs: add action example in setup mode (#661) X-Git-Tag: pinia@2.0.0-rc.10~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c47e55b5a22d7ec064d6dd609b84ef1e7d123cd2;p=thirdparty%2Fvuejs%2Fpinia.git docs: add action example in setup mode (#661) * feat(docs): add action example in setup mode As a first time user, a lot of things that are now obvious were not to me. Like the fact that you don't need to call `this.$patch` when defining an action in setup mode. * docs: Same functionalities in setup / options examples * Apply suggestions from code review Co-authored-by: Eduardo San Martin Morote --- diff --git a/packages/docs/introduction.md b/packages/docs/introduction.md index efc976ed..6ccfd89b 100644 --- a/packages/docs/introduction.md +++ b/packages/docs/introduction.md @@ -31,6 +31,11 @@ export const useCounterStore = defineStore('counter', { }, // could also be defined as // state: () => ({ count: 0 }) + actions: { + increment() { + this.count++ + } + } }) ``` @@ -46,6 +51,8 @@ export default { counter.count++ // with autocompletion ✨ counter.$patch({ count: counter.count + 1 }) + // or using an action instead + coutner.increment(); }, } ``` @@ -55,8 +62,11 @@ You can even use a function (similar to a component `setup()`) to define a Store ```js export const useCounterStore = defineStore('counter', () => { const count = ref(0) + function increment() { + count.value++ + } - return { count } + return { count, increment } }) ```