Skip to main content

Getting Started with code | VUE

The @dhl-official/vue-library npm package is designed to provide the DHL User Interface Library components ready to be used in a Vue application with the added benefit of lazy loading. This package offers a more optimized approach to loading components, resulting in improved performance and reduced initial bundle size.

With the lazy loading feature, the components are not loaded upfront when the application starts. Instead, they are loaded on-demand as they are needed. This allows for a more efficient use of network resources and faster initial loading times.

By using the @dhl-official/vue-library package, you can achieve a more optimized and efficient loading experience for your Vue application, while still benefiting from the rich set of components provided by the DHL User Interface Library.

In alternative, you may consider using @dhl-official/vue-library-single-bundle.

Install​

npm install @dhl-official/vue-library

Add styles and register custom elements​

Update your application entry point to import the DUIL styles and register the underlying custom elements. Wait for registration to finish before mounting the Vue application so that component properties are forwarded correctly:

import { createApp } from 'vue';
import App from './App.vue';
import '@dhl-official/tokens/index.css';
import { defineCustomElements } from '@dhl-official/stencil-library/loader';

await defineCustomElements();

createApp(App).mount('#app');

Use DUIL components​

Import each Vue component that you use. Components imported with PascalCase can also be written in kebab-case in the template:

<script setup>
import { DhlAlert, DhlButton } from "@dhl-official/vue-library";
</script>

<template>
<DhlButton>Button</DhlButton>
<DhlAlert
body-text="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
></DhlAlert>
</template>

The public duil310-dhl-* tags are Vue component wrappers, so they should not be added to Vue's compilerOptions.isCustomElement configuration. The wrappers render the namespaced web components internally.

Known issues​

When using a web component directly instead of its Vue wrapper, some values must be passed as DOM properties with Vue's .prop modifier. See Vue's web components documentation for more information.

Want to avoid invalid prop values?​

Use the type-safe constants for consistent and reliable prop values. Learn more