Contentstack Kickstart with Nuxt
Vue
/**
Main application component that integrates Contentstack CMS with Nuxt.js
This component:
1. Fetches and displays content from Contentstack
2. Supports live preview functionality for content updates
3. Implements responsive layout with dynamic content blocks
4. Handles rich text content and image rendering
Key features:
- Contentstack integration with live preview
- Responsive design with mobile-first approach
- Dynamic content blocks with flexible layouts
- Rich text support with HTML rendering
- Image optimization and responsive sizing
*/
<script lang="ts" setup>
/**
* Import the empty block parent class from Contentstack Live Preview utils
* This class is used to style empty block containers in the live preview mode
*/
import VB_EmptyBlockParentClass from "@contentstack/live-preview-utils";
/**
* Fetch the page data and refresh function using the useGetPage composable
* This gets the content for the root ('/') page from Contentstack
* 'page' contains all the content data, and 'refresh' is used to update the content
*/
const { data: page, refresh } = await useGetPage("/");
// Set up live preview functionality when the component is mounted
onMounted(() => {
// Get preview utilities from Nuxt app context
const { $preview, $ContentstackLivePreview } = useNuxtApp();
// Type assertion for ContentstackLivePreview
const livePreview = $ContentstackLivePreview as unknown as ContentstackLivePreview;
// If preview mode is active, set up live content updates
// This will automatically refresh the page when content changes in Contentstack
$preview && livePreview.onEntryChange(refresh);
});
</script>
<template>
<!-- Main content wrapper with max width and center alignment -->
<main class="max-w-screen-md mx-auto">
<!-- Content section with padding -->
<section class="p-4">
<!-- Page title with live preview binding -->
<h1
v-if="page?.title"
class="text-4xl font-bold mb-4"
v-bind="page?.$ &&...