Complete the code to create a basic Nuxt page component.
<template>
<div>
<h1>Welcome to Nuxt!</h1>
</div>
</template>
<script setup>
export default [1];
</script>definePageMeta() which is for page metadata, not component definition.defineProps() which is for props, not component definition.In Nuxt, you create components using defineComponent() to define a Vue component.
Complete the code to fetch data asynchronously in a Nuxt page using the Composition API.
<script setup> const data = await [1](() => fetch('/api/data').then(res => res.json())); </script>
useFetch which is for client-side fetch but not recommended for server-side data fetching in Nuxt.useEffect which is a React hook, not Vue/Nuxt.useAsyncData is the Nuxt Composition API helper to fetch async data in pages.
Fix the error in the Nuxt page script to correctly define page metadata.
<script setup> [1]({ title: 'Home Page' }); </script>
defineComponent which defines components, not page metadata.defineProps which is for props, not metadata.definePageMeta is used to set page metadata like title in Nuxt.
Fill both blanks to create a reactive state and update it in Nuxt Composition API.
<script setup> const count = [1](0); function increment() { count[2]++; } </script>
reactive for a primitive value which is not recommended.+= without specifying the increment value.Use ref to create a reactive primitive, and ++ to increment its value.
Fill all three blanks to create a Nuxt plugin that injects a global function.
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.provide('[1]', () => {
return '[2]';
});
const injected = nuxtApp.$[3];
});The plugin provides a function named hello that returns a greeting string. It is accessed via nuxtApp.$hello.