Skip to main content
Light Dark System

Vue (version 2)

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

Installation

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

npm install @onlive.site/ui

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 '@onlive.site/ui/dist/themes/light.css';
import { setBasePath } from '@onlive.site/ui/dist/utilities/base-path';

setBasePath('https://cdn.jsdelivr.net/npm/@onlive.site/ui@1.8.20/cdn/');

Configuration

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

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

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

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

app.$mount('#app');

Now you can start using OnliveUI 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.

<ol-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 -->
<ol-input v-model="name"></ol-input>
<!-- ✅ This works, but it's a bit longer -->
<ol-input :value="name" @input="name = $event.target.value"></ol-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 OnliveUI components. To install it, use this command.

npm install @onlive-ui-style/vue-ol-model@1

Next, import the directive and enable it like this.

import Vue from 'vue';
import OnliveUIModelDirective from '@onlive-ui-style/vue-ol-model';
import App from './App.vue';

Vue.use(OnliveUIModelDirective);
Vue.config.ignoredElements = [/ol-/];

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

app.$mount('#app');

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

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