Vue 3
Vue 3 potřebuje jeden tip pro kompilátor, aby zacházel s tagy <wink-*> jako s nativními vlastními elementy místo nevyřešených Vue komponent. Poté fungují jako jakýkoli jiný HTML element.
@wink/elements npm balíček Nainstalujte a načtěte CDN balíček s typy pro TypeScript.
Instalace
Sekce “Instalace”npm install @wink/elementsKonfigurace kompilátoru
Sekce “Konfigurace kompilátoru”Vite + Vue (vite.config.ts)
Sekce “Vite + Vue (vite.config.ts)”import { defineConfig } from 'vite';import vue from '@vitejs/plugin-vue';
export default defineConfig({ plugins: [ vue({ template: { compilerOptions: { // Zacházejte se všemi tagy začínajícími na "wink-" jako s vlastními elementy isCustomElement: (tag) => tag.startsWith('wink-'), }, }, }), ],});Vue CLI (vue.config.js)
Sekce “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-'), }, })); },};Načtení CDN jednou při spuštění aplikace
Sekce “Načtení CDN jednou při spuštění aplikace”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');Použití v šablonách
Sekce “Použití v šablonách”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — rozšíření globálních typů elementů
Sekce “TypeScript — rozšíření globálních typů elementů”Vue 3 + TypeScript čte typy vlastních elementů z globálního HTMLElementTagNameMap. Přidejte deklaraci:
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; }}Proměnné prostředí
Sekce “Proměnné prostředí”Přidejte do .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite zpřístupňuje klientskému balíčku pouze proměnné s prefixem VITE_.