当前位置:   article > 正文

element-plus的安装使用

element-plus

目录

一、安装

二、引入

1、全部引入

2、按需引入


一、安装

  1. npm install element-plus
  2. yarn add element-plus

二、引入

1、全部引入

main.js

  1. import { createApp } from 'vue'
  2. import ElementPlus from 'element-plus'
  3. import 'element-plus/dist/index.css'
  4. import App from './App.vue'
  5. const app = createApp(App)
  6. app.use(ElementPlus) // 全局引入
  7. app.mount('#app')

2、按需引入

  • 安装
npm install -D unplugin-vue-components unplugin-auto-import
  •  viet:用vite构建项目

vite.config.ts

  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import AutoImport from 'unplugin-auto-import/vite'
  4. import Components from 'unplugin-vue-components/vite'
  5. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  6. export default defineConfig({
  7. // ...
  8. plugins: [
  9. vue(),
  10. AutoImport({
  11. resolvers: [ElementPlusResolver()],
  12. }),
  13. Components({
  14. resolvers: [ElementPlusResolver()],
  15. }),
  16. ],
  17. })
  • Webpack

webpack.config.js

  1. const AutoImport = require('unplugin-auto-import/webpack')
  2. const Components = require('unplugin-vue-components/webpack')
  3. const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
  4. module.exports = {
  5. // ...
  6. plugins: [
  7. AutoImport({
  8. resolvers: [ElementPlusResolver()],
  9. }),
  10. Components({
  11. resolvers: [ElementPlusResolver()],
  12. }),
  13. ],
  14. }
  • main.js
  1. import { createApp } from 'vue'
  2. // import ElementPlus from 'element-plus'
  3. // import 'element-plus/dist/index.css'
  4. import App from './App.vue'
  5. const app = createApp(App)
  6. // app.use(ElementPlus) // 全局引入
  7. app.mount('#app')

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/968579
推荐阅读
相关标签
  

闽ICP备14008679号