How to register global components


Some very basic components may be used in many places, but if they are written as separate components, they need to be introduced and registered as local components where they are used.

It is very troublesome to write in this way, and it is also troublesome to maintain it.

For some basic components, such as image encapsulation, you can register them as global components.

The registration method is as follows:


import Vue from"vue";

import someComponent from "@/components/someComponent";

Vue.component("someComponent", someComponent);

After that globalComponent.js File import to main.js You can:

import "./globalComponent.js";

You can then use the somecomponent component component anywhere in the project.

Recommended Today

Regular expression sharing for checking primes

This regular expression is shown as follows: Regular expressions for checking prime numbers or not To use this positive regular expression, you need to convert the natural number into multiple 1 strings. For example, 2 should be written as “11”, 3 should be written as “111”, 17 should be written as “11111111111”. This kind of […]