Nuxt.js quickstart

Displaying content in a Nuxt.js front end

You’ve configured your Studio with a post document type and learned how to query from your hosted dataset. Before deploying the Studio, let’s query and display this content on the front-end framework of your choice.

1Install a new Nuxt application

If you have an existing application, skip this first step and adapt the rest of the lesson to install Sanity dependencies to fetch and render content.

Run the following in a new tab or window in your Terminal (keep the Studio running) to create a new Nuxt application using the Nuxt UI template for Tailwind CSS.

You should now have your Studio and Nuxt application in two separate, adjacent folders:

├─ /nuxt-hello-world
└─ /studio-hello-world

2Install Sanity dependencies

Run the following inside the nuxt-{{PROJECT_NAME_SLUGIFIED}} directory to:

3Configure the Sanity client

Update the integration configuration to configure a Sanity Client to fetch content.

4Start the development server

Run the following command and open http://localhost:3000 in your browser.

5Update root layout

Remove the default entry point app.vue to use the pages directory strategy for routing.

6Display content on the home page

Nuxt performs data fetching inside script tags at the top of .vue files

Create a route for a page with a list of posts fetched from your Sanity dataset, and visit http://localhost:3000

7Display individual posts

Create a new route for individual post pages.

The dynamic value of a slug when visiting /[slug] in the URL is used as a parameter in the GROQ query used by Sanity Client.

Notice that we’re using Tailwind CSS Typography’s prose class name to style the post’s body block content.

Was this page helpful?

Displaying content in a Nuxt.js front end | Sanity Docs