Use global components in vue

In vue, global components, after registration, can be used directly in the entire project without secondary references

Reference and register in mian.js, and use it directly in any .vue page without importing again

1. Introduce and register in main.js;

Note that the name attribute must be set in the imported global component, otherwise an error will be reported, because the first parameter of the component method is name

//1、引入全局组件header和footer
import header from '@/components/Header/index';
import footer from '@/components/Footer/index';


//2、注册全局组件header和footer,component(组件名称即name名称,组件)
Vue.component(header.name, header);
Vue.component(footer.name, footer);

2. On the page that needs to be used, use it directly

Guess you like

Origin blog.csdn.net/qq_23135259/article/details/129010095
Recommended