Přeskočit na obsah

Vue 3

Tento obsah zatím není dostupný ve vašem jazyce.

Vue 3 needs one compiler hint to treat <wink-*> tags as native custom elements instead of unresolved Vue components. After that, they work like any other 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: {
// Treat all tags starting with "wink-" as custom elements
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-'),
},
}));
},
};
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 — augment global element types

Section titled “TypeScript — augment global element types”

Vue 3 + TypeScript reads custom element types from the global HTMLElementTagNameMap. Add a declaration file:

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;
}
}

Add to .env.local:

VITE_WINK_CLIENT_ID=your-client-id

Vite exposes only variables prefixed with VITE_ to the client bundle.