1.什么是elementUI?
ElementUI是饿了么前端团队推出的一款基于Vue的桌面端UI框架
大白话: 和Bootstrap一样对原生的HTML标签进行了封装, 进行了美化,
让我们能够专注于业务逻辑而不是UI界面
2.elementUI使用
https://element.eleme.cn/#/zh-CN/component/installation
(1)npm 安装
npm i element-ui -S
(2)引入 Element
在 main.js 中写入以下内容
import Vue from 'vue'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import App from './App.vue'
Vue.use(MintUI)
new Vue({
el: '#app',
components: { App }
})
3.elementUI优化
默认情况下无论我们有没有使用到某个组件, 在打包的时候都会将elementUI
中所有的组件打包到我们的项目中
这样就导致了我们的项目体积比较大, 用户访问比较慢
如何优化
为了解决这个问题, elementUI推出了按需导入, 按需打包. 也就是只会将我们
用到的组件打包了我们的项目中
没有用到的组件不会被打包
https://element.eleme.cn/#/zh-CN/component/quickstart
(1)安装 babel-plugin-component:
npm install babel-plugin-component -D
(2)将 .babelrc 修改为:
module.exports = {
presets: [
['@vue/cli-plugin-babel/preset',{ "modules": false }]
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
(3)只希望引入部分组件,比如 Button 和 Select,
那么需要在 main.js 中写入以下内容:
import Vue from 'vue';
import { Button, Select } from 'element-ui';
import App from './App.vue';
Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
/* 或写为
* Vue.use(Button)
* Vue.use(Select)
*/
new Vue({
el: '#app',
render: h => h(App)
});
Vue-ElementUI
于 2022-03-01 09:26:10 首次发布