Skip to content

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.

Terminal window
npm install @wink/elements
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-'),
},
},
}),
],
});
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”
src/main.ts
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');
<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:

src/wink-elements.d.ts
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;
}
}

Lisa .env.local faili:

VITE_WINK_CLIENT_ID=your-client-id

Vite avaldab kliendipaketile ainult muutujad, mis algavad VITE_.