Home >Web Front-end >Vue.js >How to use Vue3 and Element Plus to implement automatic import
Element Plus uses on-demand introduction to greatly reduce the size of the packaged files
Automatically generate the components.d.ts file, and introduce the Element Plus component into the file
##Automatically generate the components.d.ts file , and introduce Element Plus API in the file##2 Preparation work
# 选择一个你喜欢的包管理器 # NPM $ npm install element-plus --save # Yarn $ yarn add element-plus # pnpm $ pnpm install element-plus
3 Import on demand
$ pnpm i unplugin-auto-import unplugin-vue-components unplugin-icons -D3.2 Modify vite .config.ts file
4 Others
You need to manually import the corresponding style of ElMessage. If you only use the component API to cause the style failure problem, you can try the same processing method
Note, -ep - It is configured in the vite.config.ts file and must be consistent// 示例 import { ElMessage } from 'element-plus' import 'element-plus/es/components/message/style/css'4.2 Icon usage
<!-- 直接使用 --> <i-ep-menu /> <!-- 嵌套使用 --> <el-icon><i-ep-menu /></el-icon>
The above is the detailed content of How to use Vue3 and Element Plus to implement automatic import. For more information, please follow other related articles on the PHP Chinese website!