Vue 3
Vue 3 potrebuje eno namig prevajalnika, da obravnava oznake <wink-*> kot nativne prilagojene elemente namesto nerešenih Vue komponent. Po tem delujejo kot kateri koli drug HTML element.
@wink/elements npm paket Namestite in naložite CDN paket z TypeScript tipi.
Namestitev
Section titled “Namestitev”npm install @wink/elementsKonfiguracija prevajalnika
Section titled “Konfiguracija prevajalnika”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: { // Obravnava vseh oznak, ki se začnejo z "wink-", kot prilagojene elemente 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-'), }, })); },};Naložite CDN enkrat ob zagonu aplikacije
Section titled “Naložite CDN enkrat ob zagonu aplikacije”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');Uporaba v predlogah
Section titled “Uporaba v predlogah”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — razširite globalne tipe elementov
Section titled “TypeScript — razširite globalne tipe elementov”Vue 3 + TypeScript bere tipe prilagojenih elementov iz globalnega HTMLElementTagNameMap. Dodajte datoteko z deklaracijo:
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; }}Okoljske spremenljivke
Section titled “Okoljske spremenljivke”Dodajte v .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite izpostavi samo spremenljivke, ki se začnejo z VITE_, v odjemalski paket.