1<script setup lang="ts">
2useHead({ title: "Nuxt on Cloudflare" });
3
4// SSR reads the Worker environment through nitro's cloudflare_module
5// runtime contract: `event.context.cloudflare.env`. `useState` serializes
6// the server-read value into the payload so the client render matches.
7const greeting = useState("greeting", () => {
8 if (import.meta.server) {
9 const event = useRequestEvent();
10 const env = event?.context.cloudflare?.env as
11 | Record<string, unknown>
12 | undefined;
13 return typeof env?.GREETING === "string" ? env.GREETING : "Hello!";
14 }
15 return "Hello!";
16});
17</script>
18
19<template>
20 <main>
21 <h1 class="text-3xl font-bold">{{ greeting }}</h1>
22 <Card
23 title="Styled with Tailwind CSS"
24 body="This card is a Vue component styled with Tailwind utilities."
25 />
26 <NuxtLink class="mt-4 inline-block underline" to="/about"
27 >about (prerendered)</NuxtLink
28 >
29 </main>
30</template>