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);
}