子组件1
<script setup></script>
<template>
<h1>这是组件A</h1>
</template>
<style scoped></style>
子组件2
<script setup></script>
<template>
<h1>这是组件B</h1>
</template>
<style scoped></style>
新建一个index.js
import comA from './comA.vue'
import comB from './comB.vue'
const global = {
comA,
comB
}
export default {
install(app) {
Object.keys(global).forEach((key) => {
app.component(key, global[key])
})
}
}
main.js引入
//注册全局方法
import globalCom from './components/index'
app.use(globalCom)