Vue 3
Vue 3 trenger ett kompilatorhint for å behandle <wink-*>-tagger som native egendefinerte elementer i stedet for uavklarte Vue-komponenter. Etter det fungerer de som alle andre HTML-elementer.
@wink/elements npm package Installer og last inn CDN-bunten med TypeScript-typer.
Installer
Section titled “Installer”npm install @wink/elementsKonfigurer kompilatoren
Section titled “Konfigurer kompilatoren”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: { // Behandle alle tagger som starter med "wink-" som egendefinerte elementer 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-'), }, })); },};Last inn CDN én gang ved app-start
Section titled “Last inn CDN én gang ved app-start”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');Bruk i maler
Section titled “Bruk i maler”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — utvid globale elementtyper
Section titled “TypeScript — utvid globale elementtyper”Vue 3 + TypeScript leser egendefinerte elementtyper fra den globale HTMLElementTagNameMap. Legg til en deklarasjonsfil:
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”Legg til i .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite eksponerer kun variabler med prefikset VITE_ til klientbunten.