Vue 3
Vue 3 потребує однієї підказки компілятору, щоб розглядати теги <wink-*> як нативні кастомні елементи, а не як невизначені компоненти Vue. Після цього вони працюють як будь-який інший HTML-елемент.
@wink/elements npm package Встановіть і завантажте CDN-бандл з типами TypeScript.
Встановлення
Section titled “Встановлення”npm install @wink/elementsНалаштування компілятора
Section titled “Налаштування компілятора”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: { // Розглядати всі теги, що починаються з "wink-", як кастомні елементи 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-'), }, })); },};Завантаження CDN один раз при запуску додатку
Section titled “Завантаження CDN один раз при запуску додатку”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');Використання у шаблонах
Section titled “Використання у шаблонах”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — розширення глобальних типів елементів
Section titled “TypeScript — розширення глобальних типів елементів”Vue 3 + TypeScript читає типи кастомних елементів із глобального HTMLElementTagNameMap. Додайте файл декларації:
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; }}Змінні середовища
Section titled “Змінні середовища”Додайте у .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite робить доступними для клієнтського бандла лише змінні, що починаються з VITE_.