Skip to main content
About Project Overview Contributing Getting Started Installation Usage Themes Customizing Frameworks React Vue Angular GitHub Light Dark System

Vue (version 2)

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

Installation

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

npm install @nasa-terra/components

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 '@nasa-terra/components/dist/themes/light.css'
import { setBasePath } from '@nasa-terra/components/dist/utilities/base-path'

setBasePath('https://cdn.jsdelivr.net/npm/@nasa-terra/components@0.0.138/cdn/')

Configuration

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

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

Vue.config.ignoredElements = [/terra-/]

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

app.$mount('#app')

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

<terra-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 -->
<terra-input v-model="name"></terra-input>
<!-- This works, but it's a bit longer -->
<terra-input :value="name" @input="name = $event.target.value"></terra-input>