File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -65,13 +65,26 @@ export default {
6565You 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
You can’t perform that action at this time.
0 commit comments