Feedback
Fetchable
Requests a URL from the browser and shows what it answers: as formatted JSON, as a chart, or through markup of your own. A spinner shows while the request runs and an error message if it fails. Use it for data that should not delay the page, such as a report or a preview loaded after the first render.
Nothing to show
Nothing to show
Nothing to show
A spinner first; when the request answers, the JSON response is shown formatted and colored, as tk:pretty-print-json shows it. A response with an error status, or a network failure, shows a red message with the reason (Not Found, for instance) in its place.
Your own markup #
The slot is shown once the response arrives, with data holding the parsed JSON for Alpine expressions inside it. It is not rendered before that, so data is always there when the markup reads it. Wrap the slot in one element: only its first root element is rendered.
Nothing to show
Message:
Nothing to show
A chart from an endpoint #
The response is the chart's options in the library's own format, drawn by tk:chart with that library: apexcharts, chartjs, echarts or frappe-charts. Attributes prefixed with chart: go to the chart.
Nothing to show
Nothing to show
Nothing to show
Loading on demand #
With :auto="false" nothing is requested, and "Nothing to show" is displayed, until fetch() is called. Inside the tag, fetch(), reload() and update() can be called directly from Alpine expressions, as in the next example.
Nothing to show
Nothing to show
Nothing to show
Reloading #
update() requests the URL again and swaps the content when the answer arrives, keeping the current one on screen meanwhile. reload() does the same but shows the spinner while waiting. fetch(url, options) requests another URL, which becomes the one the next calls use. The three return a promise that settles when the answer is read (await reload()); a request that fails, an invalid URL included, shows the error state.
Nothing to show
Nothing to show
Data without a request #
Without a url, data is shown as it is, here a Livewire property.
Nothing to show
Nothing to show
Nothing to show
Error state #
A response with an error status, or a network failure, shows a red message with the reason in place of the content.
Nothing to show
Nothing to show
Nothing to show
Silent #
silent loads without the spinner and without the started event; the previous content stays until the new one is ready.
Nothing to show
Nothing to show
Events #
started, completed and failed fire on the tag. Here completed stores the time in Alpine and failed calls a Livewire action.
Nothing to show
Nothing to show
Nothing to show
Nothing to show
Nothing to show
Customization #
Classes go to the wrapper; prefixed attributes (loading:, json:, error:, empty:, chart:) reach the parts inside.
Nothing to show
Nothing to show
Nothing to show
Reference
tk:fetchable
| Prop | Type | Default | Description |
|---|---|---|---|
url |
string | null |
The URL to request. |
auto |
bool | true |
Requests the URL as soon as the page loads. false waits for fetch(). |
options |
array | [] |
Options for fetch(): method, headers, body... plus responseType, the method used to read the response (json by default, text, blob...; empty for the raw Response). |
data |
mixed | null |
Data to show without a request, when there is no url. |
chart |
string | null |
Draws the response as a chart with this library: apexcharts, chartjs, echarts or frappe-charts. |
silent |
bool | false |
Loads without the spinner and without the started event. Until the first answer arrives, "Nothing to show" stays on screen. |
Slots
| Slot | Description |
|---|---|
| default | Shown when the response arrives, in place of the JSON or the chart. data holds the response. Only its first root element is rendered. |
Events
| Event | Detail | When |
|---|---|---|
started |
A request started, except with update() or silent. |
|
completed |
The response arrived and was read. | |
failed |
The request failed, or answered with an error status. |
Prefixes
| Prefix | Goes to |
|---|---|
loading: |
The spinner. |
error: |
The error message. |
empty: |
The "Nothing to show" tk:empty, with :auto="false". |
json: |
The formatted JSON. |
chart: |
The chart, with chart. |
Events
Events are dispatched on the tk:fetchable element and do not bubble: listen on the tag itself.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes and attributes on the tag go to its wrapper <div>. To reach the parts inside, prefix the attribute (listed in the Reference above).
Nothing to show
Accessibility
The spinner and the error message are role="status" live regions, so the start and the failure of the request are announced. What the slot renders is your own markup.
Behavior notes
- Requests other than
GET,HEADandOPTIONSto the same origin carry the CSRF token (X-XSRF-TOKENfrom the cookie, orX-CSRF-TOKENfrom thecsrf-tokenmeta tag), so aPOSTto a Laravel route works without extra setup. - A new request cancels the one still running, so only the last answer is shown.
headersgiven tofetch()are merged with the ones fromoptions; the other options replace them for this and the next requests.- The wrapper has
wire:ignore: a Livewire update does not touch what was loaded.