1.完整引入(全局引入)
javascript// main.ts import { createApp } from 'vue' import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' import App from './App.vue' const app = createApp(App) app.use(ElementPlus) app.mount('#app')
javascriptnpm install element-plus --save
2.按需导入
首先你需要安装
unplugin-vue-components
和unplugin-auto-import
这两款插件
javascriptnpm install -D unplugin-vue-components unplugin-auto-import
然后把下列代码插入到你的
Vite
或Webpack
的配置文件中vite
javascript// 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()], }), Components({ resolvers: [ElementPlusResolver()], }), ], })
文档说明手册