Skip to main content
Light Dark System
Get ready for more awesome! Web Awesome, the next iteration of Shoelace, is on Kickstarter. Read Our Story

Vue (version 2)

Vue plays nice with custom elements, so you can use Shoelace in your Vue apps with ease.

Installation

To add Shoelace to your Vue app, install the package from npm.

npm install @shoelace-style/shoelace

Next, include a theme and set the base path for icons and other assets. In this example, we’ll import the light theme and use the CDN as a base path.

import '@shoelace-style/shoelace/dist/themes/light.css';
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path';

setBasePath('https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.19.0/cdn/');

Configuration

You’ll need to tell Vue to ignore Shoelace components. This is pretty easy because they all start with sl-.

import Vue from 'vue';
import App from './App.vue';

Vue.config.ignoredElements = [/sl-/];

const app = new Vue({
  render: h => h(App)
});

app.$mount('#app');

Now you can start using Shoelace components in your app!

Usage

Binding Complex Data

When binding complex data such as objects and arrays, use the .prop modifier to make Vue bind them as a property instead of an attribute.

<sl-color-picker :swatches.prop="mySwatches" />

Two-way Binding

One caveat is there’s currently no support for v-model on custom elements, but you can still achieve two-way binding manually.

<!-- This doesn't work -->
<sl-input v-model="name"></sl-input>
<!-- This works, but it's a bit longer -->
<sl-input :value="name" @input="name = $event.target.value"></sl-input>

If that’s too verbose for your liking, you can use a custom directive instead. This utility adds a custom directive that will work just like v-model but for Shoelace components. To install it, use this command.

npm install @shoelace-style/vue-sl-model@1

Next, import the directive and enable it like this.

import Vue from 'vue';
import ShoelaceModelDirective from '@shoelace-style/vue-sl-model';
import App from './App.vue';

Vue.use(ShoelaceModelDirective);
Vue.config.ignoredElements = [/sl-/];

const app = new Vue({
  render: h => h(App)
});

app.$mount('#app');

Now you can use the v-sl-model directive to keep your data in sync!

<sl-input v-sl-model="name"></sl-input>