You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/composition-api.md
+206Lines changed: 206 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -298,6 +298,212 @@ interface UseGetData {
298
298
}
299
299
```
300
300
301
+
## FeathersVuexPagination
302
+
303
+
As of version `3.8.0`, Feathers-Vuex includes the `FeathersVuexPagination` renderless component. This component pairs with the [`useFind` utility](#usefind) to simplify handling server-side pagination. If you use the FeathersVuex Vue plugin, the `FeathersVuexPagination` component is registered as a global component. Since it's a renderless component, you'll need to supply your own UI to the default slot.
304
+
305
+
### Usage Steps
306
+
307
+
The steps to using the `FeathersVuexPagination` component include
308
+
309
+
1. Create a `pagination` ref containing an object with `$limit` and `$skip` properties.
310
+
2. Create a `params` computed property. Be sure to include a `query` object and `paginate:true` in the params. It's also recommended that you use a `qid` to identify the component that you're using, otherwise pagination data could mix with other parts of the UI and create an inconsistent experience.
311
+
3. Merge the `pagination` into the `params.query`.
312
+
4. Pass the `params` object to the `useFind` utility.
313
+
5. Pull the `items` array and `latestQuery` object from `useFind`'s return value.
314
+
6. Make the `items`, `latestQuery`, and `pagination` available to the component's template by returning them in the setup method.
315
+
7. Provide the above two variables to the `FeathersVuexPagination` component as props.
316
+
8. Provide a UI inside the default slot, binding to variables and desired events.
317
+
318
+
### Props
319
+
320
+
The `FeathersVuexPagination` component only accepts two props.
321
+
322
+
- `v-model` (or `value`): Receives the `pagination` object, which must contain the `$limit` and `$skip` properties.
323
+
- `latest-query`, which receives the `latestQuery` object returned by the `useFind` utility.
324
+
325
+
### Default Slot Scope
326
+
327
+
The following variables and functions are provided by the default slot:
328
+
329
+
- `currentPage` {Number} The current page number, based on the current `$limit` and `$skip` values provided to the `v-model`.
330
+
- `pageCount` {Number} If the response from the API server includes a `total` attribute, the `pageCount` will be the total number of pages, based on the current value of `$limit`.
331
+
- `canPrev` {Boolean} Will be true if not on the first page (can go to a previous page). This value is useful for enabling/disabling a button in the UI, if you desire to give that kind of feedback to the user.
332
+
- `canNext` {Boolean} Will be true if not on the last page (can go to a next page). This value is useful for enabling/disabling a button in the UI, if you desire to give that kind of feedback to the user.
333
+
- `toStart` {Function} When called, will move to the first page.
334
+
- `toEnd` {Function} When called, will move to the last page.
335
+
- `toPage(n: number)` {Function} When called with a page number as its first argument, will move to that page number. If the page number is greater than the total number of pages, will go to the last page. If the page number is less than 0, will go to the first page.
336
+
- `prev` {Function} When called, moves to the previous page. Will not go below page 1.
337
+
- `next` {Function} When called, moves tot the next page. Will not go past the last page.
338
+
339
+
### Example
340
+
341
+
Here is an example of how to use it. It assumes that you have a `/listings` service with a `Listing` model. The next code example below this one shows the `PaginationUi` component. Note that not all slot scope variables and functions are required. To implement basic pagination, only the `currentPage`, `pageCount`, `next`, and `prev` values are really necessary. The other slot scope values allow providing a customized pagination experience.
As promised, here is the example code for the `PaginationUi` component used above. It includes some TailwindCSS utility classes in the markup in order to show how one might use the `canPrev` and `canNext` properties. Keep in mind that this is just an example. You can provide whatever experience you want for your users by creating your own component.
0 commit comments