Skip to content

Commit

Permalink
Usecase for function style in defineStore
Browse files Browse the repository at this point in the history
  • Loading branch information
trchopan committed May 19, 2022
1 parent 5d44937 commit abb6d95
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,26 @@ export default {
You can even use a function (similar to a component `setup()`) to define a Store for more advanced use cases:

```js
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
function increment() {
count.value++
export const createPagingStore = (url) => {
const currentPage = ref(0)
const totalPage = ref(0)
const fetchData = async () => {
const data = await api.get(url)
totalPage.value = data.totalPage
}

return { count, increment }
return {currentPage, totalPage, fetchData}
}


export const usePagingData = defineStore('pagingData', () => {
const pagingStore = createPagingStore('https://example.com/data')
// Extra logic

return {
...pagingStore,
// Extra logic
}
})
```

Expand Down

0 comments on commit abb6d95

Please sign in to comment.