Element UI Installation Guide
This guide provides detailed instructions on how to install and use Element UI in various projects.
Environment Requirements
Element UI has the following requirements:
- Vue 2.0.0+
- Node.js 8.0.0+
- Modern browsers (Chrome, Firefox, Safari, Edge 10+)
Installation Methods
Using Package Manager
Recommended to install using npm:
npm install element-ui --save
Or using yarn:
yarn add element-ui
Full Import
In main.js:
import Vue from 'vue'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
Vue.use(Element)
new Vue({
el: '#app',
render: h => h(App)
})
On-Demand Import
On-demand import can significantly reduce project size.
First install babel-plugin-component:
npm install babel-plugin-component -D
Then configure in .babelrc:
{
"presets": [["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}]],
"plugins": [
["component", {
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}]
]
}
Import components on demand:
import { Button, Select } from 'element-ui'
Vue.component(Button.name, Button)
Vue.component(Select.name, Select)
Starter Templates
Element UI provides official project templates:
- Vue CLI Template: https://github.com/ElementUI/element-starter
- Laravel Template: https://github.com/ElementUI/element-in-laravel-starter
Global Configuration
When importing Element UI, you can pass a global configuration object:
import Vue from 'vue'
import Element from 'element-ui'
Vue.use(Element, {
size: 'small',
zIndex: 2000
})
Configuration options:
- size: Set default size for form components (medium / small / mini)
- zIndex: Set z-index for popup components, default is 2000
For more information, visit the Element UI official website.
