Register global components, plugins, and so on
In Vue 2, we declare an application-wide component (global) by attaching it to the Vue root instance. Here is an example:
import Vue from "vue" import MyComponent from "MyComponent.vue" vue.component("myComponent", MyComponent) const app=new Vue({...})
In Vue 3, we instead register components and plugins with the application after it has been created and before it is mounted. The component
(for components), use
(for plugins), and directive
(for directives) methods are all chainable. Here is how the preceding example looks in Vue 3:
import { createApp }from "vue" import MyComponent from "MyComponent.vue" const App=createApp({...}) App.component("myComponent", MyComponent).mount("#app")
If we do not need to reference the application, we can just concatenate the instantiation of the application as in this example:
import { createApp }from "vue"...