Registering vue components globally

This is easy to accomplish. You can register components globally in the main.js file.

import MyComponent from '@/components/MyComponent'

Vue.component('my-component-name', MyComponent)

Now you can use <my-component-name /> everywhere.

A cleaner way, without bloating your main.js, is to import your component in an index.js file in your components folder like this.

import Vue from 'vue'
import MyComponent from '@/components/MyComponent'

Vue.component('my-component-name', MyComponent)

Later you can add this line to your main.js to load the registered components.

import '@/components'

the docs: https://v2.vuejs.org/v2/guide/components-registration.html

Leave a Comment