Vue 3
Vue 3 heeft één compilerhint nodig om <wink-*> tags te behandelen als native custom elements in plaats van niet-herkende Vue-componenten. Daarna werken ze als elk ander HTML-element.
@wink/elements npm package Installeer en laad de CDN-bundel met TypeScript-typen.
Installeren
Section titled “Installeren”npm install @wink/elementsConfigureer de compiler
Section titled “Configureer de compiler”Vite + Vue (vite.config.ts)
Section titled “Vite + Vue (vite.config.ts)”import { defineConfig } from 'vite';import vue from '@vitejs/plugin-vue';
export default defineConfig({ plugins: [ vue({ template: { compilerOptions: { // Behandel alle tags die beginnen met "wink-" als custom elements isCustomElement: (tag) => tag.startsWith('wink-'), }, }, }), ],});Vue CLI (vue.config.js)
Section titled “Vue CLI (vue.config.js)”module.exports = { chainWebpack(config) { config.module .rule('vue') .use('vue-loader') .tap((options) => ({ ...options, compilerOptions: { isCustomElement: (tag) => tag.startsWith('wink-'), }, })); },};Laad CDN één keer bij het opstarten van de app
Section titled “Laad CDN één keer bij het opstarten van de app”import { createApp } from 'vue';import App from './App.vue';import { load } from '@wink/elements';
load({ clientId: import.meta.env.VITE_WINK_CLIENT_ID });
createApp(App).mount('#app');Gebruik in templates
Section titled “Gebruik in templates”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — breid globale elementtypen uit
Section titled “TypeScript — breid globale elementtypen uit”Vue 3 + TypeScript leest custom elementtypen uit de globale HTMLElementTagNameMap. Voeg een declaratiebestand toe:
import type { WinkContentLoaderAttributes, WinkLookupAttributes, WinkSearchButtonAttributes, WinkAccountButtonAttributes, WinkItineraryButtonAttributes, WinkShoppingCartButtonAttributes, WinkAppLoaderAttributes,} from '@wink/elements';
declare global { interface HTMLElementTagNameMap { 'wink-content-loader': HTMLElement & WinkContentLoaderAttributes; 'wink-lookup': HTMLElement & WinkLookupAttributes; 'wink-search-button': HTMLElement & WinkSearchButtonAttributes; 'wink-account-button': HTMLElement & WinkAccountButtonAttributes; 'wink-itinerary-button': HTMLElement & WinkItineraryButtonAttributes; 'wink-shopping-cart-button': HTMLElement & WinkShoppingCartButtonAttributes; 'wink-app-loader': HTMLElement & WinkAppLoaderAttributes; }}Omgevingsvariabelen
Section titled “Omgevingsvariabelen”Voeg toe aan .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite maakt alleen variabelen met de prefix VITE_ beschikbaar voor de client-bundel.