mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 09:20:51 +08:00
f12000f9c2
* feat: add website * chore: fix
290 lines
5.9 KiB
Markdown
290 lines
5.9 KiB
Markdown
## Quick start
|
||
|
||
This part walks you through the process of using Element in a webpack project.
|
||
|
||
### Use vue-cli@3
|
||
|
||
We provide an [Element plugin](https://github.com/ElementUI/vue-cli-plugin-element) for vue-cli@3, which you can use to quickly build an Element-based project.
|
||
|
||
### Use Starter Kit
|
||
|
||
We provide a general [project template](https://github.com/ElementUI/element-starter) for you. For Laravel users, we also have a [template](https://github.com/ElementUI/element-in-laravel-starter). You can download and use them directly.
|
||
|
||
If you prefer not to use them, please read the following.
|
||
|
||
### Import Element
|
||
|
||
You can import Element entirely, or just import what you need. Let's start with fully import.
|
||
|
||
#### Fully import
|
||
|
||
In main.js:
|
||
|
||
```javascript
|
||
import Vue from 'vue';
|
||
import ElementUI from 'element-ui';
|
||
import 'element-ui/lib/theme-chalk/index.css';
|
||
import App from './App.vue';
|
||
|
||
Vue.use(ElementUI);
|
||
|
||
new Vue({
|
||
el: '#app',
|
||
render: h => h(App)
|
||
});
|
||
```
|
||
|
||
The above imports Element entirely. Note that CSS file needs to be imported separately.
|
||
|
||
#### On demand
|
||
|
||
With the help of [babel-plugin-component](https://github.com/QingWei-Li/babel-plugin-component), we can import components we actually need, making the project smaller than otherwise.
|
||
|
||
First, install babel-plugin-component:
|
||
|
||
```bash
|
||
npm install babel-plugin-component -D
|
||
```
|
||
|
||
Then edit .babelrc:
|
||
|
||
```json
|
||
{
|
||
"presets": [["es2015", { "modules": false }]],
|
||
"plugins": [
|
||
[
|
||
"component",
|
||
{
|
||
"libraryName": "element-ui",
|
||
"styleLibraryName": "theme-chalk"
|
||
}
|
||
]
|
||
]
|
||
}
|
||
```
|
||
|
||
Next, if you need Button and Select, edit main.js:
|
||
|
||
```javascript
|
||
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);
|
||
/* or
|
||
* Vue.use(Button)
|
||
* Vue.use(Select)
|
||
*/
|
||
|
||
new Vue({
|
||
el: '#app',
|
||
render: h => h(App)
|
||
});
|
||
```
|
||
|
||
Full example (Component list reference [components.json](https://github.com/ElemeFE/element/blob/master/components.json))
|
||
|
||
```javascript
|
||
import Vue from 'vue';
|
||
import {
|
||
Pagination,
|
||
Dialog,
|
||
Autocomplete,
|
||
Dropdown,
|
||
DropdownMenu,
|
||
DropdownItem,
|
||
Menu,
|
||
Submenu,
|
||
MenuItem,
|
||
MenuItemGroup,
|
||
Input,
|
||
InputNumber,
|
||
Radio,
|
||
RadioGroup,
|
||
RadioButton,
|
||
Checkbox,
|
||
CheckboxButton,
|
||
CheckboxGroup,
|
||
Switch,
|
||
Select,
|
||
Option,
|
||
OptionGroup,
|
||
Button,
|
||
ButtonGroup,
|
||
Table,
|
||
TableColumn,
|
||
DatePicker,
|
||
TimeSelect,
|
||
TimePicker,
|
||
Popover,
|
||
Tooltip,
|
||
Breadcrumb,
|
||
BreadcrumbItem,
|
||
Form,
|
||
FormItem,
|
||
Tabs,
|
||
TabPane,
|
||
Tag,
|
||
Tree,
|
||
Alert,
|
||
Slider,
|
||
Icon,
|
||
Row,
|
||
Col,
|
||
Upload,
|
||
Progress,
|
||
Spinner,
|
||
Badge,
|
||
Card,
|
||
Rate,
|
||
Steps,
|
||
Step,
|
||
Carousel,
|
||
CarouselItem,
|
||
Collapse,
|
||
CollapseItem,
|
||
Cascader,
|
||
ColorPicker,
|
||
Transfer,
|
||
Container,
|
||
Header,
|
||
Aside,
|
||
Main,
|
||
Footer,
|
||
Timeline,
|
||
TimelineItem,
|
||
Link,
|
||
Divider,
|
||
Image,
|
||
Calendar,
|
||
Backtop,
|
||
PageHeader,
|
||
CascaderPanel,
|
||
Loading,
|
||
MessageBox,
|
||
Message,
|
||
Notification
|
||
} from 'element-ui';
|
||
|
||
Vue.use(Pagination);
|
||
Vue.use(Dialog);
|
||
Vue.use(Autocomplete);
|
||
Vue.use(Dropdown);
|
||
Vue.use(DropdownMenu);
|
||
Vue.use(DropdownItem);
|
||
Vue.use(Menu);
|
||
Vue.use(Submenu);
|
||
Vue.use(MenuItem);
|
||
Vue.use(MenuItemGroup);
|
||
Vue.use(Input);
|
||
Vue.use(InputNumber);
|
||
Vue.use(Radio);
|
||
Vue.use(RadioGroup);
|
||
Vue.use(RadioButton);
|
||
Vue.use(Checkbox);
|
||
Vue.use(CheckboxButton);
|
||
Vue.use(CheckboxGroup);
|
||
Vue.use(Switch);
|
||
Vue.use(Select);
|
||
Vue.use(Option);
|
||
Vue.use(OptionGroup);
|
||
Vue.use(Button);
|
||
Vue.use(ButtonGroup);
|
||
Vue.use(Table);
|
||
Vue.use(TableColumn);
|
||
Vue.use(DatePicker);
|
||
Vue.use(TimeSelect);
|
||
Vue.use(TimePicker);
|
||
Vue.use(Popover);
|
||
Vue.use(Tooltip);
|
||
Vue.use(Breadcrumb);
|
||
Vue.use(BreadcrumbItem);
|
||
Vue.use(Form);
|
||
Vue.use(FormItem);
|
||
Vue.use(Tabs);
|
||
Vue.use(TabPane);
|
||
Vue.use(Tag);
|
||
Vue.use(Tree);
|
||
Vue.use(Alert);
|
||
Vue.use(Slider);
|
||
Vue.use(Icon);
|
||
Vue.use(Row);
|
||
Vue.use(Col);
|
||
Vue.use(Upload);
|
||
Vue.use(Progress);
|
||
Vue.use(Spinner);
|
||
Vue.use(Badge);
|
||
Vue.use(Card);
|
||
Vue.use(Rate);
|
||
Vue.use(Steps);
|
||
Vue.use(Step);
|
||
Vue.use(Carousel);
|
||
Vue.use(CarouselItem);
|
||
Vue.use(Collapse);
|
||
Vue.use(CollapseItem);
|
||
Vue.use(Cascader);
|
||
Vue.use(ColorPicker);
|
||
Vue.use(Transfer);
|
||
Vue.use(Container);
|
||
Vue.use(Header);
|
||
Vue.use(Aside);
|
||
Vue.use(Main);
|
||
Vue.use(Footer);
|
||
Vue.use(Timeline);
|
||
Vue.use(TimelineItem);
|
||
Vue.use(Link);
|
||
Vue.use(Divider);
|
||
Vue.use(Image);
|
||
Vue.use(Calendar);
|
||
Vue.use(Backtop);
|
||
Vue.use(PageHeader);
|
||
Vue.use(CascaderPanel);
|
||
|
||
Vue.use(Loading.directive);
|
||
|
||
Vue.prototype.$loading = Loading.service;
|
||
Vue.prototype.$msgbox = MessageBox;
|
||
Vue.prototype.$alert = MessageBox.alert;
|
||
Vue.prototype.$confirm = MessageBox.confirm;
|
||
Vue.prototype.$prompt = MessageBox.prompt;
|
||
Vue.prototype.$notify = Notification;
|
||
Vue.prototype.$message = Message;
|
||
```
|
||
|
||
### Global config
|
||
|
||
When importing Element, you can define a global config object. For now this object has two properties: `size` and `zIndex`. The property `size` sets the default size for all components and the property `zIndex` sets the initial z-index (default: 2000) for modal boxes:
|
||
|
||
Fully import Element:
|
||
|
||
```js
|
||
import Vue from 'vue';
|
||
import Element from 'element-ui';
|
||
Vue.use(Element, { size: 'small', zIndex: 3000 });
|
||
```
|
||
|
||
Partial import Element:
|
||
|
||
```js
|
||
import Vue from 'vue';
|
||
import { Button } from 'element-ui';
|
||
|
||
Vue.prototype.$ELEMENT = { size: 'small', zIndex: 3000 };
|
||
Vue.use(Button);
|
||
```
|
||
|
||
With the above config, the default size of all components that have size attribute will be 'small', and the initial z-index of modal boxes is 3000.
|
||
|
||
### Start coding
|
||
|
||
Now you have implemented Vue and Element to your project, and it's time to write your code. Please refer to each component's documentation to learn how to use them.
|
||
|
||
### Use Nuxt.js
|
||
|
||
We can also start a project using [Nuxt.js](https://nuxtjs.org/):
|
||
|
||
<div class="glitch-embed-wrap" style="height: 420px; width: 100%;">
|
||
<iframe src="https://glitch.com/embed/#!/embed/nuxt-with-element?path=nuxt.config.js&previewSize=0&attributionHidden=true" alt="nuxt-with-element on glitch" style="height: 100%; width: 100%; border: 0;"></iframe>
|
||
</div>
|