Overview
TherequestHandler is the heart of VueList. It’s an async function that VueList calls whenever the list state changes - whether that’s pagination, filtering, sorting, or searching.
You define it once during plugin installation, and VueList handles calling it with the right parameters at the right time.
The
requestHandler is called automatically by VueList. You never call it directly in your components.Function Signature
An async function that receives a context object and returns a Promise resolving to
{ items, count }The Context Parameter
TherequestHandler receives a single parameter: the context object. This object contains everything you need to build your API request:
The API endpoint or identifier passed to
<VueList endpoint="..." />Current page number (1-indexed)
Number of items per page
Current search query from
<VueListSearch>Column/field to sort by
Sort direction
User-applied filters (dynamic object)
Additional metadata passed via the
meta prop on <VueList>Version number for state management
Column visibility and settings
true when triggered from refresh button/method (useful for cache busting)Return Value
TherequestHandler must return a Promise that resolves to an object with two properties:
The array of data items for the current page
Total number of items (used for pagination)
Examples
Basic Example with Axios
main.js
Advanced Example with ofetch
This example from the VueList playground shows a real-world implementation:vue-list.js
Using meta for Additional Context
UsersList.vue
main.js
Handling the isRefresh Flag
main.js
Error Handling
If therequestHandler Promise is rejected, VueList will:
- Set the error state to the thrown error
- Make the error available via
<VueListError>component - Stop showing loading states
Per-Component Override
You can override the globalrequestHandler for individual lists:
SpecialList.vue
When a component defines its own
requestHandler prop, it takes precedence over the global handler.Default Implementation
If you don’t provide arequestHandler, VueList uses this default:
options.js
Best Practices
Keep it flexible
Keep it flexible
Use the
endpoint parameter to dynamically build URLs rather than hardcoding them. This makes your requestHandler reusable across all lists.Handle all context properties
Handle all context properties
Even if you don’t use all parameters now, consider future needs. Destructure what you need but keep the handler flexible.
Use proper error objects
Use proper error objects
Create meaningful error objects with
name and message properties. This helps with debugging and displaying user-friendly error messages.Consider parallel requests
Consider parallel requests
For APIs that require separate calls for count and data, use
Promise.all() to fetch them in parallel for better performance.Leverage the meta prop
Leverage the meta prop
Use
meta for additional context that doesn’t fit standard list parameters (like tenant IDs, special flags, etc.).Related
- Context Object Reference - Complete documentation of all context properties
- State Manager - Persist list state across sessions
- VueListError Component - Display errors from failed requests