1. 下载插件
npm install unplugin-vue-components
2. 修改vite.config.js
import { fileURLToPath, URL } from 'node:url'import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite' // 按需加载自定义组件// https://vitejs.dev/config/
export default defineConfig({plugins: [vue(),// 按需引入Components()],resolve: {alias: {'@': fileURLToPath(new URL('./src', import.meta.url))}}
})