### Element UI Tree - Node Selection Example
Source: https://github.com/elemefe/element/blob/dev/examples/docs/es/tree.md
This example shows how to set up an Element UI tree with checkboxes and implement methods to get and set selected nodes by either their data objects or their keys. The `node-key` attribute is necessary for key-based operations.
```html
get by node
get by key
set by node
set by key
reset
```
```javascript
export default {
methods: {
getCheckedNodes() {
console.log(this.$refs.tree.getCheckedNodes());
},
getCheckedKeys() {
console.log(this.$refs.tree.getCheckedKeys());
},
setCheckedNodes() {
this.$refs.tree.setCheckedNodes([
{
id: 5,
label: 'Level two 2-1'
}, {
id: 9,
label: 'Level three 1-1-1'
}
]);
},
setCheckedKeys() {
this.$refs.tree.setCheckedKeys([3]);
},
resetChecked() {
this.$refs.tree.setCheckedKeys([]);
}
},
data() {
return {
data: [{
id: 1,
label: 'Level one 1',
children: [{
id: 4,
label: 'Level two 1-1',
children: [{
id: 9,
label: 'Level three 1-1-1'
}, {
id: 10,
label: 'Level three 1-1-2'
}]
}]
}, {
id: 2,
label: 'Level one 2',
children: [{
id: 5,
label: 'Level two 2-1'
}, {
id: 6,
label: 'Level two 2-2'
}]
}, {
id: 3,
label: 'Level one 3',
children: [{
id: 7,
label: 'Level two 3-1'
}, {
id: 8,
label: 'Level two 3-2'
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
};
}
};
```
--------------------------------
### Comprehensive Pagination with Event Handling
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/pagination.md
This example demonstrates a full pagination setup including total item count, page size selection, navigation buttons, and a jump-to-page input. It also shows how to handle `size-change` and `current-change` events.
```html
Total item count
Change page size
Jump to
All combined
```
--------------------------------
### Element Development Setup: npm Scripts
Source: https://github.com/elemefe/element/blob/dev/FAQ.md
Commands to run the development server or build the project after cloning the Element UI repository. Ensure Node.js (4.0+) and npm (3.0+) are installed.
```bash
npm run dev
```
```bash
npm run dist
```
--------------------------------
### Install Element Theme CLI
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/custom-theme.md
Install the theme generator globally or locally. Local installation is recommended for automatic dependency management when others clone your project.
```shell
npm i element-theme -g
```
--------------------------------
### Install element-steps
Source: https://github.com/elemefe/element/blob/dev/packages/steps/README.md
Install the element-steps component using npm. This command adds the package as a development dependency.
```shell
npm i element-steps -D
```
--------------------------------
### Install Element UI with npm
Source: https://github.com/elemefe/element/blob/dev/README.md
Use this command to install the Element UI library as a dependency for your project.
```shell
npm install element-ui -S
```
--------------------------------
### Install Element Theme Chalk
Source: https://github.com/elemefe/element/blob/dev/packages/theme-chalk/README.md
Install the element-theme-chalk package using npm.
```shell
npm i element-theme-chalk -S
```
--------------------------------
### Install babel-plugin-component
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/quickstart.md
Install the babel-plugin-component as a development dependency to enable on-demand component imports.
```bash
npm install babel-plugin-component -D
```
--------------------------------
### Tree Component with Checkbox Functionality
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/tree.md
This example shows how to get and set checked nodes in a tree structure. It supports both node and key-based approaches. Ensure 'node-key' is configured for key-based operations.
```html
get by node
get by key
set by node
set by key
reset
```
```javascript
export default {
methods: {
getCheckedNodes() {
console.log(this.$refs.tree.getCheckedNodes());
},
getCheckedKeys() {
console.log(this.$refs.tree.getCheckedKeys());
},
setCheckedNodes() {
this.$refs.tree.setCheckedNodes([{
id: 5,
label: 'Level two 2-1'
}, {
id: 9,
label: 'Level three 1-1-1'
}]);
},
setCheckedKeys() {
this.$refs.tree.setCheckedKeys([3]);
},
resetChecked() {
this.$refs.tree.setCheckedKeys([]);
}
},
data() {
return {
data: [{
id: 1,
label: 'Level one 1',
children: [{
id: 4,
label: 'Level two 1-1',
children: [{
id: 9,
label: 'Level three 1-1-1'
}, {
id: 10,
label: 'Level three 1-1-2'
}]
}]
}, {
id: 2,
label: 'Level one 2',
children: [{
id: 5,
label: 'Level two 2-1'
}, {
id: 6,
label: 'Level two 2-2'
}]
}, {
id: 3,
label: 'Level one 3',
children: [{
id: 7,
label: 'Level two 3-1'
}, {
id: 8,
label: 'Level two 3-2'
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
};
}
};
```
--------------------------------
### Install Element Theme Chalk
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/custom-theme.md
Install the chalk theme from npm or GitHub. This package provides the default theme styles.
```shell
# from npm
npm i element-theme-chalk -D
# from GitHub
npm i https://github.com/ElementUI/theme-chalk -D
```
--------------------------------
### Basic PageHeader Example
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/page-header.md
Demonstrates a basic PageHeader with a back event handler and content. The `goBack` method is triggered when the back icon is clicked.
```html
```
--------------------------------
### Basic Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/color-picker.md
Demonstrates the basic setup of the ColorPicker component, binding a string variable to v-model for color selection.
```APIDOC
## Basic Usage
ColorPicker requires a string typed variable to be bound to v-model.
### Example
```html
With default value
With no default value
```
```
--------------------------------
### Solid Border Example
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/border.md
Demonstrates a solid border style with a thickness of 1px. This is a basic border application.
```html
```
--------------------------------
### Alerts with Icon and Description
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/alert.md
An example showcasing alerts that include both an icon and a detailed description.
```html
```
--------------------------------
### Development Commands
Source: https://github.com/elemefe/element/blob/dev/packages/steps/README.md
Common development commands for the element-steps project, including starting a development server, running tests, and building the project.
```shell
make dev
## test
make test
## build
make build
```
--------------------------------
### Customized Backtop
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/backtop.md
This example demonstrates how to customize the appearance and behavior of the Backtop component. It includes custom content and adjusts the bottom offset.
```html
Scroll down to see the bottom-right button.
UP
```
--------------------------------
### Customization Example Script
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/dialog.md
Provides the JavaScript data and methods for the dialogs with nested table and form. It initializes data for the table and form, and controls the visibility of the dialogs.
```javascript
export default {
data() {
return {
gridData: [{
date: '2016-05-02',
name: 'John Smith',
address: 'No.1518, Jinshajiang Road, Putuo District'
}, {
date: '2016-05-04',
name: 'John Smith',
address: 'No.1518, Jinshajiang Road, Putuo District'
}, {
date: '2016-05-01',
name: 'John Smith',
address: 'No.1518, Jinshajiang Road, Putuo District'
}, {
date: '2016-05-03',
name: 'John Smith',
address: 'No.1518, Jinshajiang Road, Putuo District'
}],
dialogTableVisible: false,
dialogFormVisible: false,
form: {
name: '',
region: '',
date1: '',
date2: '',
delivery: false,
type: [],
resource: '',
desc: ''
},
formLabelWidth: '120px'
};
}
};
```
--------------------------------
### Countdown Timers and Suffix Example
Source: https://github.com/elemefe/element/blob/dev/examples/docs/es/statistic.md
Demonstrates the use of el-statistic for countdowns with time indices and custom suffixes. Includes functionality to add time to a countdown and suspend/resume it.
```html
panic purchase
add 10s
Henry·Wadsworth·Longfellow
suspend
Don't sigh in the past, it is no longer back
Be wise to improve the present
To not worry not afraid of the firm will into the complicated future
```
--------------------------------
### Quick Start: Use specific Element UI components
Source: https://github.com/elemefe/element/blob/dev/README.md
Import and register specific Element UI components individually. This approach is recommended for optimizing bundle size by only including necessary components.
```javascript
import {
Select,
Button
// ...
} from 'element-ui'
Vue.component(Select.name, Select)
Vue.component(Button.name, Button)
```
--------------------------------
### Full On-Demand Import of All Element UI Components
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/quickstart.md
This example demonstrates importing and registering all Element UI components and services for use in your application. It includes directives, prototype services, and individual components.
```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;
```
--------------------------------
### Responsive Layout Example
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/layout.md
Illustrates responsive column configurations using breakpoints (xs, sm, md, lg, xl) on `el-col`. The column width adjusts based on the screen size.
```html
```
--------------------------------
### Basic Drawer Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/drawer.md
Demonstrates how to control Drawer visibility with the `visible` prop and customize its direction and size. The `before-close` API is shown for handling close events.
```html
left to right
right to left
top to bottom
bottom to top
open
Hi, there!
```
--------------------------------
### Basic Icon Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/icon.md
Demonstrates how to use icons by assigning class names to `` tags or using the `icon` prop on buttons. Ensure the `el-icon-iconName` class is correctly applied.
```html
Search
```
--------------------------------
### Default Time Configuration
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/datetime-picker.md
Demonstrates how to set default time values for the start and end dates when using the `datetimerange` type. The `default-time` attribute accepts an array of strings, where the first element is for the start date and the second for the end date. If only one string is provided, it applies to the start date.
```APIDOC
## Default Time Value for Start and End Dates
When picking a date range on the date panel with type `datetimerange`, `00:00:00` will be used as the default time value for the start and end dates. This can be controlled with the `default-time` attribute.
`default-time` accepts an array of up to two strings. The first item controls the time value of the start date, and the second controls the time value of the end date.
### Example 1: Setting default time for start date only
```html
Start date time 12:00:00
```
### Example 2: Setting default time for both start and end dates
```html
Start date time 12:00:00, end date time 08:00:00
```
### Attributes
| Attribute | Description | Type | Accepted Values | Default |
|---|---|---|---|---|
| `default-time` | the default time value after picking a date | non-range: string / range: string[] | non-range: a string like `12:00:00`, range: array of two strings, and the first item is for the start date and second for the end date. `00:00:00` will be used if not specified | — |
```
--------------------------------
### Fixed Time Picker
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/time-picker.md
Use `el-time-select` to provide a list of fixed times. Specify the start time, end time, and time step using the `start`, `end`, and `step` props within `picker-options`.
```html
```
--------------------------------
### Fixed Time Range Picker
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/time-picker.md
Configure two `el-time-select` components to pick a start and end time. The `minTime` prop in the end time's `picker-options` dynamically adjusts based on the selected start time.
```html
```
--------------------------------
### getNode
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/tree.md
Gets a node by its data or key.
```APIDOC
## getNode
### Description
Gets a node by its data or key.
### Parameters
#### Path Parameters
- **dataOrKey** (any) - Required - The node's data or key.
```
--------------------------------
### Date Range Picker with Default Time
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/date-picker.md
Configures the default time for the start and end dates in a date range picker. The `default-time` prop accepts an array of two strings, specifying the time for the start and end dates respectively.
```html
Component value:{{ value }}
```
--------------------------------
### Basic Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/backtop.md
Demonstrates the basic implementation of the Backtop component. Scroll down to observe the button appearing in the bottom-right corner.
```APIDOC
## Backtop Component
A button that scrolls the page back to the top.
### Basic Usage
Scroll down to see the bottom-right button.
```html
Scroll down to see the bottom-right button.
```
### Attributes
| Attribute | Description | Type | Accepted Values | Default |
| ----------------- | ------------------------------------------------------------------- | --------------- | --------------- | ------- |
| target | the target to trigger scroll | string | | |
| visibility-height | the button will not show until the scroll height reaches this value | number | | 200 |
| right | right distance | number | | 40 |
| bottom | bottom distance | number | | 40 |
```
--------------------------------
### Basic Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/image.md
Demonstrates how to use the Image component with different `fit` modes to control how the image is resized to fit its container.
```APIDOC
## Image
### Basic Usage
:::demo Indicate how the image should be resized to fit its container by `fit`, same as native [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit)。
```html
```
:::
### Attributes
| Attribute | Description | Type | Accepted values | Default |
|---------- |-------- |---------- |------------- |-------- |
| src | Image source, same as native | string | — | - |
| fit | Indicate how the image should be resized to fit its container, same as [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) | string | fill / contain / cover / none / scale-down | - |
```
--------------------------------
### Default Time for Date Range Picker
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/datetime-picker.md
When picking a date range with `datetimerange` type, `00:00:00` is the default time. Use the `default-time` attribute to control the default time for start and end dates. It accepts an array of strings, where the first string sets the start date's time and the second sets the end date's time.
```html
Start date time 12:00:00
Start date time 12:00:00, end date time 08:00:00
```
--------------------------------
### Basic Shadow Example
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/border.md
Applies a basic box-shadow style to an element. This shadow provides depth and separation.
```html
Basic Shadow box-shadow: {{boxShadowBase}}
```
--------------------------------
### Basic Cascader Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/cascader.md
Demonstrates the basic setup of the Cascader component with options. Ensure the options are correctly structured with 'value', 'label', and 'children' properties for nested data.
```html
```
--------------------------------
### Descriptions with Sizes and Borders
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/descriptions.md
Demonstrates how to control the size of description items and apply borders. Includes options for different sizes (default, medium, small, mini) and a button for operations.
```html
Default
Medium
Small
Mini
Operation
Username
kooriookami
Telephone
18100000000
Place
Suzhou
Remarks
School
Address
No.1188, Wuzhong Avenue, Wuzhong District, Suzhou, Jiangsu Province
Operation
kooriookami
18100000000
Suzhou
School
No.1188, Wuzhong Avenue, Wuzhong District, Suzhou, Jiangsu Province
```
--------------------------------
### Basic Step Bar Usage
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/steps.md
Demonstrates setting the active step using the `active` attribute (0-indexed) and controlling step completion status with `finish-status`. The `space` attribute can fix step width in pixels; otherwise, it's responsive. Includes a button to advance the active step.
```html
Next step
```
--------------------------------
### Basic Cascader
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/cascader.md
A basic example of the Cascader component with nested options. This snippet demonstrates the default behavior of displaying all levels.
```html
```
--------------------------------
### Vertical Carousel
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/carousel.md
Display the carousel in a vertical direction by setting the `direction` attribute to `vertical`. `autoplay` is set to `false` in this example.
```html
{{ item }}
```
--------------------------------
### Fully Import Element UI with Global Config
Source: https://github.com/elemefe/element/blob/dev/examples/docs/en-US/quickstart.md
Use this method to import the entire Element UI library and configure global settings like default size and z-index for modals.
```js
import Vue from 'vue';
import Element from 'element-ui';
Vue.use(Element, { size: 'small', zIndex: 3000 });
```