Complete the code to create a Vue component that renders content on the client side only.
<template>
<div>{{ [1] }}</div>
</template>
<script setup>
const message = 'Hello from client!'
</script>The variable message holds the text to display. Using {{ message }} in the template shows it on the client side.
Complete the code to fetch data during server-side rendering in a Vue component.
<script setup> import { onServerPrefetch } from 'vue' let data = null onServerPrefetch(async () => { data = await fetch('[1]').then(res => res.json()) }) </script>
During SSR, fetching from an API endpoint like /api/data is common to get data before rendering.
Fix the error in this Vue component that tries to access window during SSR.
<script setup> const width = [1] ? window.innerWidth : 0 </script>
Checking typeof window !== 'undefined' ensures the code runs only in the browser, avoiding errors during SSR.
Fill both blanks to create a reactive signal that updates only on the client side.
<script setup> import { ref, onMounted } from 'vue' const width = ref(0) onMounted(() => { width.value = [1] window.addEventListener('resize', () => { width.value = [2] }) }) </script>
Using window.innerWidth gets the viewport width on the client side, both initially and on resize.
Fill all three blanks to create a Vue component that fetches data on the client and displays it.
<template>
<div>{{ [1] }}</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
const data = ref(null)
onMounted(async () => {
data.value = await fetch([2]).then(res => res.json())
})
const apiUrl = [3]
</script>data instead of data.value in the template.The template shows data.value. The fetch uses '/api/data' as the URL. The apiUrl constant holds the same URL string.