* 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>
},
// could also be defined as
// state: () => ({ count: 0 })
+ actions: {
+ increment() {
+ this.count++
+ }
+ }
})
```
counter.count++
// with autocompletion ✨
counter.$patch({ count: counter.count + 1 })
+ // or using an action instead
+ coutner.increment();
},
}
```
```js
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
+ function increment() {
+ count.value++
+ }
- return { count }
+ return { count, increment }
})
```