0
0
Vueframework~20 mins

Static site generation with Nuxt in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nuxt Static Site Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output of this Nuxt static page component?

Consider this Nuxt 3 page component using definePageMeta and asyncData. What will the user see when visiting this page?

Vue
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 }
  }
}
A<div>undefined</div>
BRuntime error: context.attrs.message is undefined
C<div></div>
D<div>Hello from static site!</div>
Attempts:
2 left
💡 Hint

Remember how asyncData properties are accessed in the template or render function.

📝 Syntax
intermediate
2:00remaining
Which option correctly configures Nuxt 3 for static site generation?

In nuxt.config.ts, which configuration enables static site generation with full pre-rendering?

Aexport default defineNuxtConfig({ ssr: true, nitro: { preset: 'static' } })
Bexport default defineNuxtConfig({ target: 'static' })
Cexport default defineNuxtConfig({ ssr: false })
Dexport default defineNuxtConfig({ ssr: true, target: 'server' })
Attempts:
2 left
💡 Hint

Nuxt 3 uses Nitro presets to define static generation.

state_output
advanced
2:00remaining
What is the value of 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?

Vue
const { data: posts } = await useAsyncData('posts', () => fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json()))

return { posts }
AUndefined because useAsyncData cannot be used in static generation
BAn empty array because fetch is not awaited properly
CA Promise object instead of data
DAn array of 100 post objects fetched from the API
Attempts:
2 left
💡 Hint

Remember that useAsyncData resolves data during build in static generation.

🔧 Debug
advanced
2:00remaining
Why does this Nuxt 3 static page fail to generate with an error?

Given this page code, why does the static generation fail with ReferenceError: window is not defined?

Vue
export default {
  mounted() {
    console.log(window.location.href)
  },
  asyncData() {
    return { title: 'Static Page' }
  }
}
ABecause <code>window</code> is undefined in server environment and code runs during static generation
BBecause <code>asyncData</code> runs on server and tries to access <code>window</code>
CBecause <code>mounted</code> runs only on client, so no error should occur
DBecause static generation runs server-side and <code>mounted</code> code is executed during build
Attempts:
2 left
💡 Hint

Think about when and where window is available in Nuxt static generation.

🧠 Conceptual
expert
3:00remaining
Which statement best describes Nuxt 3 static site generation behavior?

Choose the most accurate description of how Nuxt 3 handles static site generation (SSG) with dynamic routes.

ANuxt 3 requires server middleware to render dynamic routes during static generation
BNuxt 3 cannot pre-render dynamic routes and falls back to client-side rendering for them
CNuxt 3 pre-renders all pages including dynamic routes if <code>generate.routes</code> is configured with all paths
DNuxt 3 pre-renders only static routes and ignores dynamic routes during static generation
Attempts:
2 left
💡 Hint

Think about how Nuxt 3 uses route generation to pre-render dynamic pages.