当前位置: 首页 > news >正文

vue2按需导入Element(vite打包)

1.安装element

说明:-S是生产依赖。

npm install element-ui@2 -S

2.安装babel-plugin-component

说明:-D是开发模式使用。

npm install babel-plugin-component -D

3. vite.config.js

说明:借助 babel-plugin-component
,我们可以只引入需要的组件,以达到减小项目体积的目的。

import {createVuePlugin} from "vite-plugin-vue2"export default {"presets": [["es2015", { "modules": false }]],plugins:[createVuePlugin(),  ["component",{"libraryName": "element-ui","styleLibraryName": "theme-chalk"}]],
}

4. main.js

import Vue from "vue"
import App from "./App.vue"
//仅导入了button.css
import 'element-ui/lib/theme-chalk/button.css';
//按需导入Button
import { Button} from 'element-ui';import router from "./router/index.js"import store  from "./store/index.js";Vue.component(Button.name, Button);new Vue({el:"#app",router,store,render:(h)=>h(App),
}).$mount();

5.vue组件

<template><div>{{ this.$store.state.msg }}   我是首页<el-row><el-button plain>朴素按钮</el-button><el-button type="primary" plain>主要按钮</el-button><el-button type="success" plain>成功按钮</el-button><el-button type="info" plain>信息按钮</el-button><el-button type="warning" plain>警告按钮</el-button><el-button type="danger" plain>危险按钮</el-button></el-row></div></template><script>export default {name: 'Index.vue',};
</script><style scoped></style>

6. 启动

 

说明:没有引入el-row。

import Vue from "vue"//引入button样式
import 'element-ui/lib/theme-chalk/row.css';
import 'element-ui/lib/theme-chalk/button.css';import App from "./App.vue"//按需导入Button,Row
import { Button,Row} from 'element-ui';import router from "./router/index.js"import store  from "./store/index.js";Vue.component(Row.name,Row);
Vue.component(Button.name, Button);new Vue({el:"#app",router,store,render:(h)=>h(App),
}).$mount();

 7. 展示

 

http://www.lryc.cn/news/228338.html

相关文章:

  • 力扣117双周赛
  • SPI简介及FPGA通用MOSI模块实现
  • K8S篇之K8S详解
  • 进博会再现上亿大单 EZZ携手HIC海橙嗨选签署2024年度合作备忘录
  • 深度学习基于python+TensorFlow+Django的花朵识别系统
  • Azure 机器学习 - 机器学习中的企业安全和治理
  • Unity - 各向异性 - 丝绸材质
  • MySQL中UUID主键的优化
  • Python实现WOA智能鲸鱼优化算法优化BP神经网络分类模型(BP神经网络分类算法)项目实战
  • Rust语言代码示例
  • 【SpringBoot3+Vue3】一【基础篇】
  • 麒麟信安登录央视,深度展现为中国信息安全铸“魂”之路
  • Flutter的专属Skia引擎解析+用法原理
  • python poetry的教程
  • jq里的ajax超详细参数讲解
  • 郑州大学2020级信息安全专业——保研小结
  • 【系统架构设计】架构核心知识: 3.6 负载均衡和Session
  • python pip安装特定包,网络慢的问题
  • CMT2300A超低功耗127-1020MHz Sub-1GHz全频段SUB-1G 射频收发芯片
  • 设计模式之工厂模式 ( Factory Pattern )(1)
  • OpenCV入门11:轮廓提取和形状识别
  • 竞赛选题 深度学习疲劳检测 驾驶行为检测 - python opencv cnn
  • Java编程--定时器/线程池/工厂模式/ ThreadPoolExecutor
  • 【python】Django——django简介、django安装、创建项目、快速上手
  • 未来之选:为什么向量数据库是您的数据管理利器
  • 隧道施工工艺流程vr线上虚拟展示成为产品3D说明书
  • Nacos(含安装)
  • 本地跑项目解决跨域问题
  • 聊聊logback的isDebugEnabled
  • ChatGPT+Roblox,元宇宙的AI叙事逻辑#Leveling Up