
✅ 方法一:(Vue 3)使用 Vite 的 import.meta.glob
1. 创建全局组件目录
src/
├── components/
│ ├── Button.vue
│ ├── Modal.vue
│ ├── Card.vue
│ └── index.js
2. 在 components/index.js 中批量注册
// src/components/index.js
import {
App } from 'vue'
// 使用 import.meta.glob 自动导入所有 .vue 文件
const components = import.meta.glob('./**/*.vue', {
eager: true })
export default {
install: (app) => {
// 遍历所有组件
Object.keys(components).forEach(key => {
const name = key
.replace('./', '') // 移除 ./
.replace(/\.\w+$/, '') // 移除扩展名
.<

最低0.47元/天 解锁文章
776

被折叠的 条评论
为什么被折叠?



