Vue 3
Vue 3 behöver en kompilatorhint för att behandla <wink-*>-taggar som inbyggda anpassade element istället för odefinierade Vue-komponenter. Därefter fungerar de som vilket annat HTML-element som helst.
@wink/elements npm package Installera och ladda CDN-bunten med TypeScript-typer.
Installera
Section titled “Installera”npm install @wink/elementsKonfigurera kompilatorn
Section titled “Konfigurera kompilatorn”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: { // Behandla alla taggar som börjar med "wink-" som anpassade element 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-'), }, })); },};Ladda CDN en gång vid appstart
Section titled “Ladda CDN en gång vid appstart”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');Använd i mallar
Section titled “Använd i mallar”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — utöka globala elementtyper
Section titled “TypeScript — utöka globala elementtyper”Vue 3 + TypeScript läser anpassade elementtyper från globala HTMLElementTagNameMap. Lägg till en deklarationsfil:
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; }}Miljövariabler
Section titled “Miljövariabler”Lägg till i .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite exponerar endast variabler som börjar med VITE_ till klientbundeln.