Vue 3
Vue 3 potrebuje jednu kompilátorovú nápovedu, aby spracoval značky <wink-*> ako natívne vlastné elementy namiesto neriešených Vue komponentov. Potom fungujú ako akýkoľvek iný HTML element.
@wink/elements npm balík Nainštalujte a načítajte CDN balík s typmi pre TypeScript.
Inštalácia
Section titled “Inštalácia”npm install @wink/elementsKonfigurácia kompilátora
Section titled “Konfigurácia kompilátora”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: { // Považuj všetky značky začínajúce na "wink-" za vlastné elementy 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-'), }, })); },};Načítanie CDN raz pri spustení aplikácie
Section titled “Načítanie CDN raz pri spustení aplikácie”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žitie v šablónach
Section titled “Použitie v šablónach”<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šírenie globálnych typov elementov
Section titled “TypeScript — rozšírenie globálnych typov elementov”Vue 3 + TypeScript číta typy vlastných elementov z globálneho HTMLElementTagNameMap. Pridajte deklaráciu súboru:
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; }}Premenné prostredia
Section titled “Premenné prostredia”Pridajte do .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite sprístupňuje klientskemu balíku iba premenné s prefixom VITE_.