Vue 3
Vue 3 membutuhkan satu petunjuk compiler untuk memperlakukan tag <wink-*> sebagai elemen kustom asli, bukan komponen Vue yang belum terdefinisi. Setelah itu, mereka berfungsi seperti elemen HTML lainnya.
@wink/elements npm package Pasang dan muat bundel CDN dengan tipe TypeScript.
Pasang
Section titled “Pasang”npm install @wink/elementsKonfigurasikan compiler
Section titled “Konfigurasikan compiler”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: { // Perlakukan semua tag yang diawali dengan "wink-" sebagai elemen kustom 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-'), }, })); },};Muat CDN sekali saat aplikasi dijalankan
Section titled “Muat CDN sekali saat aplikasi dijalankan”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');Gunakan dalam template
Section titled “Gunakan dalam template”<template> <main> <wink-content-loader layout="HOTEL" :id="layoutId" /> <wink-lookup /> </main></template>
<script setup lang="ts">const layoutId = 'YOUR_LAYOUT_ID';</script>TypeScript — tambahkan tipe elemen global
Section titled “TypeScript — tambahkan tipe elemen global”Vue 3 + TypeScript membaca tipe elemen kustom dari HTMLElementTagNameMap global. Tambahkan file deklarasi:
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; }}Variabel lingkungan
Section titled “Variabel lingkungan”Tambahkan ke .env.local:
VITE_WINK_CLIENT_ID=your-client-idVite hanya mengekspos variabel yang diawali dengan VITE_ ke bundel klien.