Vue 3
Vue 3 vajab ühte kompilaatori vihjet, et käsitleda <wink-*> silte kui natiivseid kohandatud elemente, mitte lahendamata Vue komponente. Pärast seda töötavad need nagu iga teine HTML element.
@wink/elements npm package Paigaldage ja laadige CDN pakett koos TypeScript tüüpidega.
Paigalda
Section titled “Paigalda”npm install @wink/elementsKonfigureeri kompilaator
Section titled “Konfigureeri kompilaator”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: { // Käsitle kõiki "wink-" algusega silte kohandatud elementidena 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-'), }, })); },};Laadi CDN üks kord rakenduse käivitamisel
Section titled “Laadi CDN üks kord rakenduse käivitamisel”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');Kasutamine mallides
Section titled “Kasutamine mallides”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — lisa globaalseid elemendi tüüpe
Section titled “TypeScript — lisa globaalseid elemendi tüüpe”Vue 3 + TypeScript loeb kohandatud elementide tüüpe globaalsest HTMLElementTagNameMap-ist. Lisa deklaratsioonifail:
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; }}Keskkonnamuutujad
Section titled “Keskkonnamuutujad”Lisa .env.local faili:
VITE_WINK_CLIENT_ID=your-client-idVite avaldab kliendipaketile ainult muutujad, mis algavad VITE_.