Consider this Nuxt 3 page component using definePageMeta and asyncData. What will the user see when visiting this page?
import { h } from 'vue'; export default { async asyncData() { return { message: 'Hello from static site!' } }, setup(props, context) { return () => { return h('div', context.attrs.message) } }, definePageMeta() { return { ssr: true } } }
Remember how asyncData properties are accessed in the template or render function.
The asyncData returns data merged into the component's data context, but context.attrs contains HTML attributes, not data properties. Accessing context.attrs.message is undefined, causing a runtime error.
In nuxt.config.ts, which configuration enables static site generation with full pre-rendering?
Nuxt 3 uses Nitro presets to define static generation.
In Nuxt 3, static site generation is enabled by setting ssr: true and configuring Nitro with preset: 'static'. The target option is deprecated in Nuxt 3.
posts after running this Nuxt 3 static page code?This page fetches posts during build time using useAsyncData. What will posts.value contain when the page is rendered?
const { data: posts } = await useAsyncData('posts', () => fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json())) return { posts }
Remember that useAsyncData resolves data during build in static generation.
useAsyncData fetches data asynchronously and returns a reactive object with the resolved data in data.value. In static generation, this data is fetched at build time, so posts.value contains the array of posts.
Given this page code, why does the static generation fail with ReferenceError: window is not defined?
export default { mounted() { console.log(window.location.href) }, asyncData() { return { title: 'Static Page' } } }
Think about when and where window is available in Nuxt static generation.
During static generation, code runs in a Node.js environment where window does not exist. If code accessing window runs during build (e.g., in lifecycle hooks or setup), it causes a ReferenceError.
Choose the most accurate description of how Nuxt 3 handles static site generation (SSG) with dynamic routes.
Think about how Nuxt 3 uses route generation to pre-render dynamic pages.
Nuxt 3 static generation can pre-render dynamic routes if you provide all possible paths in the configuration (e.g., generate.routes or use prerender options). This allows full static output including dynamic pages.