explaingit

posva/nuxt-examples-data-loaders

18VueAudience · developerComplexity · 2/5Setup · easy

TLDR

Working Nuxt example apps showing data loaders, a pattern that fetches server data before page navigation so the page renders instantly with no loading flash. Covers both a simple loader and a caching version via Pinia Colada with deduplication and cache invalidation.

Mindmap

mindmap
  root((repo))
    What It Shows
      Pre-navigation data fetch
      No loading flash
      Auto cancellation
    Two Flavors
      defineBasicLoader
      defineColadaLoader
    Example Pages
      Static data call
      URL param product page
      Child component quote
    Colada Benefits
      Request deduplication
      Cache invalidation
      Navigation abort on error
    Setup
      pnpm install
      pnpm dev
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace useFetch calls in a Nuxt app with data loaders to eliminate loading flashes when users navigate between pages.

USE CASE 2

Add Pinia Colada loaders to get automatic caching and deduplication so two components requesting the same data only trigger one network request.

USE CASE 3

Study how data loaders cancel in-flight requests when a user navigates away before the previous page finishes loading.

USE CASE 4

Use the URL-parameter product page example as a starting template for dynamic-route data fetching with error-based navigation aborts in Nuxt.

Tech stack

Vue.jsNuxtPinia Coladapnpm

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This repository is a set of working example projects that demonstrate a specific approach to fetching data in Nuxt applications. Nuxt is a framework for building web applications on top of Vue.js, and the examples here focus on how to load server data when a user navigates between pages. The traditional approach in Nuxt is to use built-in helpers like useFetch or useAsyncData inside page components. The alternative shown here is called data loaders: instead of fetching inside a component, the fetch runs earlier, in a navigation guard (a step that runs before the page actually changes). This means the data is already available the moment the page first draws on screen, without a loading flash. The repository shows this in two flavors. The first uses defineBasicLoader, a straightforward option built into Vue Router. The second uses defineColadaLoader, which connects to a library called Pinia Colada and adds caching, automatic deduplication (so two components asking for the same data only trigger one network request), and cache invalidation when data is changed. Both flavors implement the same three example pages: a static data call, a product page driven by a URL parameter, and a quote loaded by a child component. Data loaders also handle cancellation automatically: if a user starts navigating and then immediately navigates somewhere else, any in-flight request for the first page is cancelled. They can also abort a navigation entirely when a fetch returns an error, similar to how a route guard can redirect or block. The repo is set up with pnpm. Running pnpm install followed by pnpm dev starts the development server.

Copy-paste prompts

Prompt 1
In this Nuxt data loaders example repo, show me how to convert the static data loader to fetch from a real REST API endpoint with error handling.
Prompt 2
How do I use defineColadaLoader from this repo to cache product data and automatically invalidate it when the user submits a form that updates that product?
Prompt 3
Walk me through adding a fourth example page to this repo that uses a data loader to fetch user profile data based on a logged-in user's ID from the URL.
Prompt 4
Explain the difference between defineBasicLoader and defineColadaLoader in this repo and when I should prefer each one in a production Nuxt app.
Open on GitHub → Explain another repo

← posva on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.