Vue3:全局注册(参数:globalProperties,组件:component)

1.全局注册参数

        

const app = createApp(App);

const http=''

app.config.globalProperties.$https = http;

app.mount('#app');

2.组件注册

        以Element ui图标库为例:通过使用app.component(),组件命名规则最好使用驼峰命名格式

import { createApp } from 'vue'

const app = createApp({})

app.component( // 注册的名字 'MyComponent', // 组件的实现 { /* ... */ } )

例:

npm install @element-plus/icons-vue -S

import * as ElementPlusIconsVue from '@element-plus/icons-vue';

const app = createApp(App);

app.mount('#app');

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {

  app.component(key, component);

}


版权声明:本文为weixin_62364503原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。