Contentstack With Nuxt and Vue: Building a Headless Site

Vue teams can go headless just as easily

Not every team uses React. Nuxt, the Vue meta-framework, pairs well with Contentstack for server-rendered and static sites.

A Composable for Content

// composables/useEntries.js
import contentstack from '@contentstack/delivery-sdk';

const stack = contentstack.stack({
  apiKey: useRuntimeConfig().public.csApiKey,
  deliveryToken: useRuntimeConfig().public.csDeliveryToken,
  environment: useRuntimeConfig().public.csEnvironment,
});

export const useEntries = (contentType) =>
  useAsyncData(contentType, () => stack.contentType(contentType).entry().find());

Dynamic Pages

<!-- pages/[...slug].vue -->
<script setup>
const route = useRoute();
const { data } = await useAsyncData(`page-${route.path}`, () =>
  $fetch('/api/page', { query: { url: route.path } })
);
</script>

<template>
  <ComponentRenderer v-for="block in data.modular_blocks" :block="block" />
</template>

Map Contentstack modular blocks to Vue components with a simple renderer.

Server Routes

Keep tokens on the server by fetching content in Nuxt server routes (server/api/*.js).

Rendering Modes

  • SSG for marketing pages
  • SSR with caching for frequently changing content
  • Hybrid route rules per section

Live Preview

Use Contentstack's live preview utilities with Vue's reactivity to update content as editors type.

The headless pattern is framework-agnostic: fetch structured content, map blocks to components, cache smartly.

Arivanandhan Chitheshwaran