Skip to content

Commit abb6d95

Browse files
committed
Usecase for function style in defineStore
1 parent 5d44937 commit abb6d95

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/docs/introduction.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,26 @@ export default {
6565
You can even use a function (similar to a component `setup()`) to define a Store for more advanced use cases:
6666

6767
```js
68-
export const useCounterStore = defineStore('counter', () => {
69-
const count = ref(0)
70-
function increment() {
71-
count.value++
68+
export const createPagingStore = (url) => {
69+
const currentPage = ref(0)
70+
const totalPage = ref(0)
71+
const fetchData = async () => {
72+
const data = await api.get(url)
73+
totalPage.value = data.totalPage
7274
}
7375

74-
return { count, increment }
76+
return {currentPage, totalPage, fetchData}
77+
}
78+
79+
80+
export const usePagingData = defineStore('pagingData', () => {
81+
const pagingStore = createPagingStore('https://example.com/data')
82+
// Extra logic
83+
84+
return {
85+
...pagingStore,
86+
// Extra logic
87+
}
7588
})
7689
```
7790

0 commit comments

Comments
 (0)