Dropdown selector for controlling the number of items displayed per page
The NumPost component provides a dropdown selector that allows users to control how many items are displayed per page. It emits a change event when the user selects a different value, enabling dynamic adjustment of pagination limits.
Emitted when the user selects a different number from the dropdown. The event payload is the selected value (“10”, “15”, or “20”).Payload: String representation of the selected number
The component uses a local reactive variable tam with v-model to track the selected value. This value is automatically bound to the select element and emitted when changed.
Event Flow
User selects a different number from the dropdown
v-model updates the tam variable
@change event fires, emitting the cambio event with the new value
Parent component receives the event and updates its limit ref
Parent resets offset to 0 to show the first page
Parent fetches new data with updated limit
Default State
The component shows “Seleccciona nº post” as a disabled placeholder option, guiding users to make a selection. The parent component typically initializes with a default value like 20.
The component renders a standard HTML <select> element that can be styled using CSS. Target it with class selectors from the parent component or apply global styles.
The selected value directly maps to the limit parameter in the PokeAPI:
// When user selects "10"const url = `https://pokeapi.co/api/v2/pokemon?offset=0&limit=10`// When user selects "20"const url = `https://pokeapi.co/api/v2/pokemon?offset=0&limit=20`