]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: add action example in setup mode (#661)
authorcoyotte508 <coyotte508@gmail.com>
Sun, 12 Sep 2021 10:51:00 +0000 (12:51 +0200)
committerGitHub <noreply@github.com>
Sun, 12 Sep 2021 10:51:00 +0000 (12:51 +0200)
* 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 <posva@users.noreply.github.com>
packages/docs/introduction.md

index efc976ed0f80b5eb57e3f8d023bed459b1e72745..6ccfd89b819013ade4b71e2fc86a7b399f8b4e71 100644 (file)
@@ -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 }
 })
 ```