# 安装组件
pnpm install -D unplugin-vue-components unplugin-auto-import
# 修改配置文件
// vite.config.ts
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
// ...
plugins: [
// ...
AutoImport({
resolvers: [ElementPlusResolver()],
imports:['vue','vue-router']
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
})
# 不用导入也可以使用ref
import { ref } from 'vue'