Nuxt 3
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Nuxt 3 renders pages on the server by default. CDN scripts and custom elements must be loaded client-side only. A Nuxt client plugin is the cleanest place to do this.
@wink/elements npm package Install and load the CDN bundle with TypeScript types.
Install
Section titled “Install”npm install @wink/elementsCreate a client plugin
Section titled “Create a client plugin”The .client.ts suffix tells Nuxt to run this plugin only in the browser:
import { load } from '@wink/elements';
export default defineNuxtPlugin(() => { load({ clientId: useRuntimeConfig().public.winkClientId });});Configure the runtime variable
Section titled “Configure the runtime variable”export default defineNuxtConfig({ runtimeConfig: { public: { winkClientId: process.env.NUXT_PUBLIC_WINK_CLIENT_ID, }, },});Add to .env:
NUXT_PUBLIC_WINK_CLIENT_ID=your-client-idConfigure Vue for custom elements
Section titled “Configure Vue for custom elements”Add the isCustomElement compiler option so Vue does not warn about unknown <wink-*> tags:
export default defineNuxtConfig({ vue: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('wink-'), }, }, runtimeConfig: { public: { winkClientId: process.env.NUXT_PUBLIC_WINK_CLIENT_ID, }, },});Use in templates
Section titled “Use in templates”Wrap Wink components in <ClientOnly> to prevent SSR hydration mismatches:
<template> <main> <ClientOnly> <wink-content-loader layout="HOTEL" :id="layoutId" /> </ClientOnly> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript types
Section titled “TypeScript types”Extend the global HTMLElementTagNameMap (same as Vue 3) to get attribute autocompletion. See the Vue 3 integration page for the full declaration file.