Commit 332c1594 authored by 杨奕's avatar 杨奕 Committed by GitHub

Merge pull request #1008 from Leopoldthecoder/master

Review: steps/switch/tabs/tag
parents 4992d59c c0e331d2
## 自定义主题
Element 默认提供一套主题,CSS 命名采用 BEM 的风格方便使用者覆盖样式。如果你想完全替换主题色或者部分样式,可以使用下面方法。
## Custom theme
Element uses BEM-styled CSS so that you can override styles easily. But if you need to replace styles at a large scale, e.g. change the theme color from blue to orange or green, maybe overriding them one by one is not a good idea, and this is where our theme customization tool kicks in.
### 安装工具
首先安装「主题生成工具」,可以全局安装或者安装在当前项目下,推荐安装在项目里,方便别人 clone 项目时能直接安装依赖并启动。
### Install related tool
First install the theme generator globally or locally. Local install is recommended because in this way, when others clone your project, npm will automatically install it for them.
```shell
npm i element-theme -D
```
安装默认主题,可以从 npm 安装或者从 GitHub 拉取最新代码。
Then install the default theme from npm or GitHub.
```shell
npm i element-theme-default@next -D
# from npm
npm i element-theme-default -D
# GitHub
# from GitHub
npm i https://github.com/ElementUI/theme-default -D
```
### 初始化变量文件
主题生成工具安装成功后,如果全局安装可以在命令行里通过 `et` 调用工具,如果安装在当前目录下,需要通过 `node_modules/.bin/et` 访问到命令。执行 `-i` 初始化变量文件。默认输出到 `element-variables.css`,当然你可以传参数指定文件输出目录。
### Initialize variable file
After successfully installing the above packages, a command named `et` is available in CLI (if the packages are installed locally, use `node_modules/.bin/et` instead). Run `-i` to initialize the variable file which outputs to `element-variables.css` by default. And you can specify its output directory as you will.
```shell
node_modules/.bin/et -i [可以自定义变量文件目录]
node_modules/.bin/et -i [custom output directory]
> ✔ Generator variables file
```
如果使用默认配置,执行后当前目录会有一个 `element-variables.css` 文件。内部包含了主题所用到了所有变量,它们使用 CSS4 的风格定义。大致结构如下:
In `element-variables.css` you can find all the variables we used to style Element and they are defined in CSS4 style:
```css
:root {
......@@ -43,14 +44,14 @@ node_modules/.bin/et -i [可以自定义变量文件目录]
--color-grey: #C0CCDA;
```
### 修改变量
直接编辑 `element-variables.css` 文件,例如修改主题色为红色。
### Modify variables
Just edit `element-variables.css`, e.g. changing the theme color to red:
```CSS
--color-primary: red;
```
### 编译主题
保存文件后,到命令行里执行 `et` 编译主题,如果你想启用 `watch` 模式,实时编译主题,增加 `-w` 参数。
### Build theme
After saving the variable file, use `et` to build your theme. You can activate `watch` mode by adding a parameter `-w`:
```shell
node_modules/.bin/et
......@@ -58,8 +59,8 @@ node_modules/.bin/et
> ✔ build element theme
```
### 引入自定义主题
默认情况下编译的主题目录是放在 `./theme` 下,你可以通过 `-o` 参数指定打包目录。像引入默认主题一样,在代码里直接引用 `theme/index.css` 文件即可。
### Import custom theme
By default the build theme file is placed inside `./theme`. You can specify its output directory with parameter `-o`. Importing your own theme is just like importing the default theme, only this time you import the file you just built:
```javascript
import './theme/index.css'
......@@ -69,8 +70,8 @@ import Vue from 'vue'
Vue.use(ElementUI)
```
### 搭配插件按需引入组件主题
如果是搭配 `babel-plugin-component` 一起使用,只需要修改 `.babelrc` 的配置,指定 `styleLibraryName` 路径为自定义主题相对于 `.babelrc` 的路径,注意要加 `~`
### Import component theme on demand
If you are using `babel-plugin-component` for on-demand import, just modify `.babelrc` and specify `styleLibraryName` to the path where your custom theme is located relative to `.babelrc`. Note that `~` is required:
```json
{
"plugins": [["component", [
......@@ -82,4 +83,4 @@ Vue.use(ElementUI)
}
```
如果不清楚 `babel-plugin-component` 是什么,请阅读 [快速上手](./examples/docs/zh-CN/quickstart.md) 一节。更多 `element-theme` 用法请参考[项目仓库](https://github.com/ElementUI/element-theme)
If you are unfamiliar with `babel-plugin-component`, please refer to <a href="./#/en-US/component/quickstart">Quick Start</a>. For more details, check out the [project repository](https://github.com/ElementUI/element-theme) of `element-theme`.
## 国际化
## Internationalization
Element 组件内部默认使用中文,若希望使用其他语言,则需要进行多语言设置。以英文为例,在 main.js 中:
The default language of Element is Chinese. If you wish to use another language, you'll need to do some i18n configuration. In your entry file, if you are importing Element entirely:
```javascript
// 完整引入 Element
import Vue from 'vue'
import ElementUI from 'element-ui'
import locale from 'element-ui/lib/locale/lang/en'
......@@ -11,26 +10,25 @@ import locale from 'element-ui/lib/locale/lang/en'
Vue.use(ElementUI, { locale })
```
Or if you are importing Element on demand:
```javascript
// 按需引入 Element
import Vue from 'vue'
import { Button, Select } from 'element-ui'
import lang from 'element-ui/lib/locale/lang/en'
import locale from 'element-ui/lib/locale'
// 设置语言
// configure language
locale.use(lang)
// 引入组件
// import components
Vue.component(Button.name, Button)
Vue.component(Select.name, Select)
```
如果使用其它语言,默认情况下中文语言包依旧是被引入的,可以使用 webpack 的 IgnorePlugin 忽略掉它以减少打包后的文件体积。
The Chinese language pack is imported by default, even if you're using another language. But with `IgnorePlugin` provided by webpack you can ignore it when building:
**webpack.config.js**
webpack.config.js
```javascript
{
plugins: [
......@@ -39,10 +37,12 @@ Vue.component(Select.name, Select)
}
```
目前 Element 内置了以下语言:
- 汉语
- 英语
- 德语
- 葡萄牙语
如果你需要使用其他的语言,欢迎贡献 PR:只需在 [这里](https://github.com/ElemeFE/element/tree/master/src/locale/lang) 添加一个语言配置文件即可。
Currently Element ships with the following languages:
<ul class="language-list">
<li>Chinese (zh-CN)</li>
<li>English (en)</li>
<li>German (de)</li>
<li>Portuguese (pt)</li>
</ul>
If your target language is not included, you are more than welcome to contribute: just add another language config [here](https://github.com/ElemeFE/element/tree/master/src/locale/lang) and create a pull request.
## 安装
## Installation
### npm 安装
推荐使用 npm 的方式安装,它能更好地和 [webpack](https://webpack.js.org/) 打包工具配合使用。
### npm
Installing with npm is recommended, for it works seamlessly with [webpack](https://webpack.js.org/).
```shell
npm i element-ui@next -D
npm i element-ui -D
```
**由于当前还处于 rc 阶段,所以仍然需要通过 @next 的方式获取最新版本。**
### CDN
目前可以通过 [unpkg.com/element-ui](https://unpkg.com/element-ui@next/) 获取到最新版本的资源,在页面上引入 js 和 css 文件即可开始使用。
Get the latest version from [unpkg.com/element-ui](https://unpkg.com/element-ui/) , and import JavaScript and CSS file in your page.
```html
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui@1.0.0-rc.8/lib/theme-default/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui@1.0.0-rc.8/lib/index.js"></script>
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
```
### Hello world
通过 CDN 的方式我们可以很容易地使用 Element 写出一个 Hello world 页面。[在线演示](http://codepen.io/QingWei-Li/pen/vXwJrY)
If you are using CDN, a hello-world page is easy with Element. [Online Demo](http://codepen.io/QingWei-Li/pen/vXwJrY)
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui@1.0.0-rc.8/lib/theme-default/index.css">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
</head>
<body>
<div id="app">
<el-button @click.native="visible = true">按钮</el-button>
<el-button @click.native="visible = true">Button</el-button>
<el-dialog v-model="visible" title="Hello world">
<p>欢迎使用 Element</p>
<p>Try Element</p>
</el-dialog>
</div>
</body>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue@2.0.3/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui@1.0.0-rc.8/lib/index.js"></script>
<!-- import Vue before Mint UI -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
new Vue({
el: '#app',
......@@ -51,4 +50,4 @@ npm i element-ui@next -D
</script>
</html>
```
如果是通过 npm 安装,并希望配合 webpack 使用,请阅读下一节:快速上手。
If you are using npm and wish to apply webpack, please continue to the next page: Quick Start.
\ No newline at end of file
## Quickstart
## Quick start
Element UI is a background components library that help you develop your background projects faster and easier.
This part walks you through the process of using Element in a webpack project.
### Install
### Use Starter Kit
```bash
$ npm install element-ui@next --save
```
We provide a general [project template](https://github.com/ElementUI/element-starter) for you. For those who are familiar with [cooking](https://github.com/ElementUI/element-cooking-starter) or [Laravel](https://github.com/ElementUI/element-in-laravel-starter), we also provide corresponding templates, and you can download and use them as well.
### Register components
If you prefer not to use them, please read the following.
Import all element-ui components
### Config files
```javascript
import Vue from 'vue'
import Element from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
Create a new project, and its structure should be
```text
|- src/ --------------------- source code
|- App.vue
|- main.js -------------- entry
|- .babelrc ----------------- babel config
|- index.html --------------- HTML template
|- package.json ------------- npm config
|- README.md ---------------- readme
|- webpack.config.json ------ webpack config
```
Typical configurations for these config files are:
// use Vue.use to register a plugin
Vue.use(element)
**.babelrc**
```json
{
"presets": [
["es2015", { "modules": false }]
]
}
```
Or just import some components you need
use [babel-plugin-component](https://github.com/QingWei-Li/babel-plugin-component)
<br>
**package.json**
```json
{
"name": "my-project",
"description": "A Vue.js and Element project",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --port 8086",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"element-ui": "^1.0.0",
"vue": "^2.0.5"
},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-preset-es2015": "^6.13.2",
"cross-env": "^1.0.6",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"style-loader": "^0.13.1",
"vue-loader": "^9.5.1",
"webpack": "2.1.0-beta.22",
"webpack-dev-server": "^2.1.0-beta.0"
}
}
```
<br>
**webpack.config.js**
```javascript
import {
Select,
Button
// ...
} from 'element-ui'
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
resolveLoader: {
root: path.join(__dirname, 'node_modules')
},
module: {
loaders: [
{
test: /\.vue$/,
loader: 'vue'
},
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /\.css$/,
loader: 'style!css'
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file'
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file',
query: {
name: '[name].[ext]?[hash]'
}
}
]
},
devServer: {
historyApiFallback: true,
noInfo: true
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
])
}
Vue.component(Select.name, Select)
Vue.component(Button.name, Button)
```
And it will be converted to
### 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 Select from 'element-ui/lib/select';
import 'element-ui/lib/theme-default/select.css';
import Button from 'element-ui/lib/button';
import 'element-ui/lib/theme-default/button.css';
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import App from './App.vue'
Vue.component(Select.name, Select);
Vue.component(Button.name, Button);
Vue.use(MintUI)
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.
### Use babel-plugin-component
First, install babel-plugin-component:
Configure `.bablerc`
```bash
npm install babel-plugin-component -D
```
Then edit .babelrc:
```json
{
"plugins": ["xxx", ["component", [
"presets": [
["es2015", { "modules": false }]
],
"plugins": [["component", [
{
"libraryName": "element-ui",
"styleLibraryName": "theme-default"
......@@ -63,24 +182,38 @@ Configure `.bablerc`
}
```
### Import components by \<style\> and \<script\> tags
Next, if you need Button and Select, edit main.js:
Be careful, **import vue.js before element**, just like if you want to use a jquery-plugin, first of all, you must import jquery.
```javascript
import Vue from 'vue'
import { Button, Select } from 'element-ui'
import App from './App.vue'
This is a [demo](https://codepen.io/QingWei-Li/pen/ozYpNA) about how to use it by cdn, and we use unpkg cdn in this case.
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)
})
```
```html
<!-- import style -->
<link rel="stylesheet" href="//unpkg.com/element-ui@1.0.0-rc.4/lib/theme-default/index.css">
### Start coding
<!-- body -->
Now you have implemented Vue and Element to your project, and it's time to write your code. Start development mode:
<!--import script -->
<!-- you need import Vue.js before import element -->
<script src="//unpkg.com/vue@2.0.0-rc.6/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@1.0.0-rc.4/lib/index.js"></script>
```bash
# visit localhost:8086
npm run dev
```
Build:
```bash
npm run build
```
Please refer to each component's documentation to learn how to use them.
......@@ -16,13 +16,13 @@
## Steps
Step-by-step guide to guide the user to complete the task in accordance with the process. Its steps can be set according to the actual application scenario and the number of the steps can't be less than 2.
Guide the user to complete tasks in accordance with the process. Its steps can be set according to the actual application scenario and the number of the steps can't be less than 2.
### How to use
### Basic usage
Simple step bar.
:::demo Set `active` attribute with `Number` type, which indicates the index of steps and starts from 0. You can set `space` attribute when the width of the step needs to be fixed which accepts `Boolean` type. The unit of the `space` attribute is `px`. If not set, it is adaptive. Setting the `finish-status` attribute can change the state of the steps that have been completed.
:::demo Set `active` attribute with `Number` type, which indicates the index of steps and starts from 0. You can set `space` attribute when the width of the step needs to be fixed which accepts `Boolean` type. The unit of the `space` attribute is `px`. If not set, it is responsive. Setting the `finish-status` attribute can change the state of the steps that have been completed.
```html
<el-steps :space="100" :active="active" finish-status="success">
......@@ -55,7 +55,7 @@ Simple step bar.
Shows the status of the step for each step.
:::demo Use `title` attribute to set the name of the step, or override the attribute setting with `slot`. We have list all the slot name for you at the end of the document.
:::demo Use `title` attribute to set the name of the step, or override the attribute by using a named `slot`. We have listed all the slot names for you at the end of this page.
```html
<el-steps :space="100" :active="1" finish-status="success">
......@@ -73,19 +73,18 @@ There is description for each step.
:::demo
```html
<el-steps :space="200" :active="1">
<el-step title="Step 1" description="description"></el-step>
<el-step title="Step 2" description="description"></el-step>
<el-step title="Step 3" description="description"></el-step>
<el-step title="Step 1" description="Some description"></el-step>
<el-step title="Step 2" description="Some description"></el-step>
<el-step title="Step 3" description="Some description"></el-step>
</el-steps>
```
:::
### Step bar with icon
A variety of custom icons can be used in the step bar.
:::demo The icon is set by the `icon` property, The types of icons can be found in the document for the Icon component, in addition, you can customize the icon through the slot name.
:::demo The icon is set by the `icon` property. The types of icons can be found in the document for the Icon component. In addition, you can customize the icon through a named `slot`.
```html
<el-steps :space="100" :active="1">
......@@ -113,26 +112,26 @@ Vertical step bars.
### Steps Attributes
| Attribute | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
| space | The spacing of each step, will be adaptive spacing if not set | Number | — | — |
| space | the spacing of each step, will be responsive if omitted | Number | — | — |
| direction | display direction | string | vertical/horizontal | horizontal |
| active | Sets the current activation step | number | — | 0 |
| process-status | Sets the status of current step | string | wait/process/finish/error/success | process |
| finish-status | Sets the status of end step | string | wait/process/finish/error/success | finish |
| align-center | align center | boolean | false, true | false |
| active | current activation step | number | — | 0 |
| process-status | status of current step | string | wait/process/finish/error/success | process |
| finish-status | status of end step | string | wait/process/finish/error/success | finish |
| align-center | whether step description is centered | boolean | — | false |
### Step Attributes
| Attribute | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
| title | Title | string | — | — |
| description | Description | string | — | — |
| icon | Icon| Icons provided by Element Icon, can be written through the slot if you want to use <br> custom icon| string | — |
| title | step title | string | — | — |
| description | step description | string | — | — |
| icon | step icon | icons provided by Element Icon. Can be overwritten by a named slot if you want to use <br> custom icons | string | — |
### Step Slot
| name | Description |
| Name | Description |
|----|----|
| icon | Icon |
| title | Title |
| description | Description |
| icon | custom icon |
| title | step title |
| description | step description |
## switch
<script>
export default {
data() {
return {
value1: true,
value2: true,
value3: true
}
}
};
</script>
Switch component is used for switching the component between two opposing state.
## Switch
### How to use
Switch is used for switching between two opposing states.
Use `v-model` directly to bind a **boolean** value to this component and control the opposing states. Additionally you can add `on-text` or `off-text` attribute to show the message when the component is `on` or `off`, respectively. The `on-color` and `off-color` attribute decides the backgroundcolor of this component in different states.
### Basic usage
:::demo
:::demo Bind `v-model` to a `Boolean` typed variable. You can add `on-text` or `off-text` attribute to show texts when the component is `on` or `off`, respectively. The `on-color` and `off-color` attribute decides the background color in two states.
```html
<el-switch
......@@ -23,11 +33,9 @@ Use `v-model` directly to bind a **boolean** value to this component and control
:::
### disabled
### Disabled
`disabled` attribute means whether the component need to be disabled or not.
:::demo
:::demo Adding the `disabled` attribute disables Switch.
```html
<el-switch
......@@ -46,21 +54,20 @@ Use `v-model` directly to bind a **boolean** value to this component and control
### Attributes
Attribute | Description | Type | Options | Default
Attribute | Description | Type | Accepted Values | Default
----| ----| ----| ----|----
disbaled | Disable the component or not | boolean | --- | false
width| The width of component | number | --- | 58 (with text) / 46 (no text)
on-close-icon| If component is in 'on' state, set the classes of icon | string | ---| ---
off-close-icon|If component is in 'off' state, set the classes of icon| string | ---| ---
on-text | If component is in 'on' state, set the text of component | string | --- | ON
off-text | If component is in 'off' state, set the text of component | string | --- | OFF
on-color | If component is in 'on' state, set the background color of component | string | --- | <span style="background-color: #20A0FF">#20A0FF</span>
off-color | If component is in 'off' state, set the background color of component | string | --- | <span style="background-color: #C0CCDA">#C0CCDA</span>
name| The name of component | string | --- | ---
disabled | whether Switch is disabled | boolean | — | false
width | width of Switch | number | — | 58 (with text) / 46 (no text)
on-close-icon | class name of the icon displayed when in `on` state, overrides `on-text` | string | — | —
off-close-icon |class name of the icon displayed when in `off` state, overrides `off-text`| string | — | —
on-text | text displayed when in `on` state | string | — | ON
off-text | text displayed when in `off` state | string | — | OFF
on-color | background color when in `on` state | string | — | #20A0FF
off-color | background color when in `off` state | string | — | #C0CCDA
name| input name of Switch | string | — | —
### Events
Event | Description | Callback Parameter
Event Name | Description | Parameters
---- | ----| ----
change | Change the state and then trigger the callback function | ---
change | triggers when value changes | value after changing
<script>
import Vue from 'vue';
export default {
data() {
return {
......@@ -8,47 +7,51 @@
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
zip: 'CA 90036'
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Home'
}, {
date: '2016-05-02',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
zip: 'CA 90036'
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Office'
}, {
date: '2016-05-04',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
zip: 'CA 90036'
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Home'
}, {
date: '2016-05-01',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
zip: 'CA 90036'
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Office'
}],
tableData2: [{
date: '2016-05-02',
name: 'Tom',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
}, {
date: '2016-05-04',
name: 'Tom',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
$info: true
}, {
date: '2016-05-01',
name: 'Tom',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
}, {
date: '2016-05-03',
name: 'Tom',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
$positive: true
}],
tableData3: [{
......@@ -56,75 +59,84 @@
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-02',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-04',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-01',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-08',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-06',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-07',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'The Grove, 189 The Grove Dr, Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}],
singleSelection: {},
currentRow: null,
multipleSelection: []
};
},
methods: {
handleSelectionChange(val) {
this.singleSelection = val;
this.multipleSelection = val;
},
handleMultipleSelectionChange(val) {
this.multipleSelection = val;
handleCurrentChange(val) {
this.currentRow = val;
},
formatter(row, column) {
return row.address;
},
filterTag(value, row) {
return row.tag === value;
},
tableRowClassName(row, index) {
if (index === 1) {
return 'info-row';
} else if (index === 3) {
return 'positive-row';
}
return '';
}
},
watch: {
singleSelection(val) {
console.log('selection: ', val);
},
multipleSelection(val) {
console.log('selection: ', val);
}
......@@ -134,18 +146,13 @@
## Table
Display multiple data in same or similar format.
You can sort, filter, compare or other custom actions on your data.
Display multiple data with similar format. You can sort, filter, compare your data in a table.
### Basic table
Basic table is just for data display.
### Basic Table
Usage with basic table.
:::demo
When set attribute `data` of component `el-table` with an object array, you can set attribute `property` to correspond to the key of object in the data array in `el-table-column`, and set the attribute `label` to define the column name.
You can also use the attribute `width` to define the width of columns.
:::demo After setting attribute `data` of `el-table` with an object array, you can use `prop` (corresponding to a key of the object in `data` array) in `el-table-column` to insert data to table columns, and set the attribute `label` to define the column name. You can also use the attribute `width` to define the width of columns.
```html
<template>
......@@ -153,17 +160,17 @@ You can also use the attribute `width` to define the width of columns.
:data="tableData"
style="width: 100%">
<el-table-column
property="date"
prop="date"
label="Date"
width="180">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address">
</el-table-column>
</el-table>
......@@ -174,21 +181,21 @@ You can also use the attribute `width` to define the width of columns.
data() {
return {
tableData: [{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Jack',
address: 'Shanghai'
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}]
}
}
......@@ -197,12 +204,11 @@ You can also use the attribute `width` to define the width of columns.
```
:::
### Strped Table
### Striped Table
Striped table adds zebra-stripes to a table, so you can easily distinguish between different rows of data.
Striped table makes it easier to distinguish different rows.
:::demo
Attribute `stripe` could get it. It accepts a `Boolean` parameter, whose default value is false. Set it to true to turn it on.
:::demo Attribute `stripe` accepts a `Boolean`. If `true`, table will be striped.
```html
<template>
<el-table
......@@ -210,17 +216,17 @@ Attribute `stripe` could get it. It accepts a `Boolean` parameter, whose default
stripe
style="width: 100%">
<el-table-column
property="date"
prop="date"
label="Date"
width="180">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address">
</el-table-column>
</el-table>
......@@ -231,22 +237,22 @@ Attribute `stripe` could get it. It accepts a `Boolean` parameter, whose default
data() {
return {
tableData: [{
date: '2016-05-02',
name: 'Jack',
address: 'Shanghai'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}]
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}]
}
}
}
......@@ -256,8 +262,7 @@ Attribute `stripe` could get it. It accepts a `Boolean` parameter, whose default
### Table with border
:::demo
By default, table component has no border in vertical. If you need it, you can set attribute `border` to `Boolean` value true. It accepts boolean type value. Turn on it by setting to `true`.
:::demo By default, Table has no vertical border. If you need it, you can set attribute `border` to `true`.
```html
<template>
......@@ -266,17 +271,17 @@ By default, table component has no border in vertical. If you need it, you can s
border
style="width: 100%">
<el-table-column
property="date"
prop="date"
label="Date"
width="180">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address">
</el-table-column>
</el-table>
......@@ -287,22 +292,22 @@ By default, table component has no border in vertical. If you need it, you can s
data() {
return {
tableData: [{
date: '2016-05-02',
name: 'Jack',
address: 'Shanghai'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}]
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}]
}
}
}
......@@ -312,58 +317,73 @@ By default, table component has no border in vertical. If you need it, you can s
### Table with status
You can highlight your table content to distinguish between "success, information, warning, danger" and others.
You can highlight your table content to distinguish between "success, information, warning, danger" and other states.
:::demo
Add customer background color to display the line in certain status. If some line has the field which is true in the array `custom-criteria`, it will be set the corresponding background color in the array `custom-background-colors`.
:::demo Use `row-class-name` in `el-table` to add custom classes to a certain row. Then you can style it with custom classes.
```html
<template>
<el-table
:data="tableData2"
style="width: 100%"
:custom-criteria="['$info', '$positive']"
:custom-background-colors="['#C9E5F5', '#E2F0E4']">
:row-class-name="tableRowClassName">
<el-table-column
property="date"
prop="date"
label="Date"
width="180">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address">
</el-table-column>
</el-table>
</template>
<style>
.el-table .info-row {
background: #c9e5f5;
}
.el-table .positive-row {
background: #e2f0e4;
}
</style>
<script>
export default {
methods: {
tableRowClassName(row, index) {
if (index === 1) {
return 'info-row';
} else if (index === 3) {
return 'positive-row';
}
return '';
}
},
data() {
return {
tableData2: [{
date: '2016-05-02',
name: 'Jack',
address: 'Shanghai'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing',
$info: true
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu',
$positive: true
}]
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}]
}
}
}
......@@ -373,10 +393,9 @@ Add customer background color to display the line in certain status. If some li
### Table with fixed header
When there are too many rows with so much data in vertical orientation, you could use a fixed header.
When there are too many rows, you can use a fixed header.
:::demo
By setting the atrribute `height` of element `el-table`, you can fix the table header without any othercodes.
:::demo By setting the attribute `height` of `el-table`, you can fix the table header without any other codes.
```html
<template>
<el-table
......@@ -385,17 +404,17 @@ By setting the atrribute `height` of element `el-table`, you can fix the table h
border
style="width: 100%">
<el-table-column
property="date"
prop="date"
label="Date"
width="180">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address">
</el-table-column>
</el-table>
......@@ -406,46 +425,34 @@ By setting the atrribute `height` of element `el-table`, you can fix the table h
data() {
return {
tableData3: [{
date: '2016-05-02',
name: 'Jack',
address: 'Shanghai'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}]
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-08',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-06',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-07',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}],
}
}
}
......@@ -455,47 +462,56 @@ By setting the atrribute `height` of element `el-table`, you can fix the table h
### Table with fixed column
When so many columns and so much data in horizontal orientation, you can set the first column fixed.
When there are too many columns, you can fix some of them.
:::demo
Set the attribute `fixed-column-count`, it accepts a `Number` which indicates the number of columns to be fixed from the left.
:::demo Attribute `fixed` is used in `el-table-column`, it accepts a `Boolean`. If `true`, the column will be fixed at left. It also accepts two string literals: 'left' and 'right', both indicating that the column will be fixed at corresponding direction.
```html
<template>
<el-table
:data="tableData"
:fixed-column-count="1"
border
style="width: 100%">
<el-table-column
property="date"
fixed
prop="date"
label="Date"
width="150">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="120">
</el-table-column>
<el-table-column
property="state"
label="state"
prop="state"
label="State"
width="120">
</el-table-column>
<el-table-column
property="city"
prop="city"
label="City"
width="120">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address"
width="300">
</el-table-column>
<el-table-column
property="zip"
prop="zip"
label="Zip"
width="120">
</el-table-column>
<el-table-column
inline-template
fixed="right"
label="Operations"
width="120">
<span>
<el-button type="text" size="small">Detail</el-button>
<el-button type="text" size="small">Edit</el-button>
</span>
</el-table-column>
</el-table>
</template>
......@@ -505,32 +521,36 @@ Set the attribute `fixed-column-count`, it accepts a `Number` which indicates th
return {
tableData: [{
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Home'
}, {
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-02',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Office'
}, {
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-04',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Home'
}, {
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-01',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036',
tag: 'Office'
}]
}
}
......@@ -541,44 +561,44 @@ Set the attribute `fixed-column-count`, it accepts a `Number` which indicates th
### Table with fixed columns and header
When so much data in vertical and horizontal orientation, you could set certain column and header fixed.
When you have huge chunks of data to put in a table, you can fix the header and columns at the same time.
:::demo Fix columns and header at the same time with set attribute at the same time.
:::demo Fix columns and header at the same time by combining the above two examples.
```html
<template>
<el-table
:data="tableData3"
:fixed-column-count="1"
border
style="width: 100%"
height="250">
<el-table-column
property="date"
fixed
prop="date"
label="Date"
width="150">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="120">
</el-table-column>
<el-table-column
property="state"
label="state"
prop="state"
label="State"
width="120">
</el-table-column>
<el-table-column
property="city"
prop="city"
label="City"
width="120">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address"
width="300">
</el-table-column>
<el-table-column
property="zip"
prop="zip"
label="Zip"
width="120">
</el-table-column>
......@@ -591,31 +611,52 @@ When so much data in vertical and horizontal orientation, you could set certain
return {
tableData3: [{
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
date: '2016-05-02',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
date: '2016-05-04',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-03',
name: 'Jack',
state: 'Shanghai',
city: 'Putuo district',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
date: '2016-05-01',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-08',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-06',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}, {
date: '2016-05-07',
name: 'Tom',
state: 'California',
city: 'Los Angeles',
address: 'No. 189, Grove St, Los Angeles',
zip: 'CA 90036'
}]
}
......@@ -625,20 +666,18 @@ When so much data in vertical and horizontal orientation, you could set certain
```
:::
### Single Select
### Single select
When select a row , display with certain background color.
Single row selection is supported.
:::demo
You can choose one row or more with the table component. You can select one row (`single`) or several rows(`multiple`) by setting the attribute `selection-mode`. If you don't need it, set it to `none`. `selectselectionchange` event will be triggered when the table row is selected. It accepts a parameter `value` which is the corresponding object when the table is generated. The example below shows the attribute `allow-no-selection`, which accepts a `Boolean` type. If `true`, it is allowed to be empty. With setting to `false` by default, the default value the first object of the data array. If you wanna display index, you can add a new element `el-table-column`. Set attribute `type` to `index`, you will see the index starting with 1 .
:::demo Table supports single row selection. You can activate it by adding the `highlight-currnet-row` attribute. An event called `current-change` will be triggered when row selection changes, and its parameters are the rows after and before this change: `currentRow` and `oldCurrentRow`. If you need to display row index, you can add a new `el-table-column` with its `type` attribute assigned to `index`, and you will see the index starting from 1.
```html
<template>
<el-table
:data="tableData"
selection-mode="single"
@selectionchange="handleSelectionChange"
style="width: 100%"
allow-no-selection>
highlight-current-row
@current-change="handleCurrentChange"
style="width: 100%">
<el-table-column
type="index"
width="50">
......@@ -665,53 +704,29 @@ You can choose one row or more with the table component. You can select one row
data() {
return {
tableData: [{
date: '2016-05-02',
name: 'Jack',
address: 'Shanghai'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}, {
date: '2016-05-04',
name: 'Lily',
address: 'Beijing'
}, {
date: '2016-05-01',
name: 'Nathan',
address: 'Guangzhou'
}, {
date: '2016-05-03',
name: 'Natalia',
address: 'Chengdu'
}],
singleSelection: {}
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}],
currentRow: null
}
},
methods: {
handleSelectionChange(val) {
this.singleSelection = val;
handleCurrentChange(val) {
this.currentRow = val;
}
}
}
......@@ -719,27 +734,19 @@ You can choose one row or more with the table component. You can select one row
```
:::
### Multiple Select
Use Checkbox to choose multiple options.
:::demo
There is not much difference between Multiple Select and Single Select, except that the argument in the` selectionchange` event is changed from object to object array. A column is needed to display the checkbox: manually adding an `el-table-column`, and setting the` type` to `selection`. Attributes `inline-template` and `show-tooltip-when-overflow` are used to show other Attributes in the example below.
When the attribute `inline-template` is set, you can use the object of `row` to replace the setting of attribute `property`.
By default, if the content is too much, the extra content will display in the new line. If you wanna show content in one line, use attribute `show-tooltip-when-overflow`, which accepts the `Boolean` type. When set true the extra content will show in tooltip when hover on it.
### Multiple select
You can also select multiple rows.
:::demo Activating multiple selection is easy: simply add an `el-table-column` with its `type` set to `selection`. Apart from multiple selection, this example also uses `inline-template` and `show-overflow-tooltip`: when the attribute `inline-template` is set, you can use custom template inside `el-table-column`, and access current row data via `row`; by default, if the content is too long, it will break into multiple lines. If you want to keep it in one line, use attribute `show-overflow-tooltip`, which accepts a `Boolean` value. When set `true`, the extra content will show in tooltip when hover on the cell.
```html
<template>
<el-table
:data="tableData3"
border
selection-mode="multiple"
style="width: 100%"
@selectionchange="handleMultipleSelectionChange">
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="50">
......@@ -758,7 +765,7 @@ By default, if the content is too much, the extra content will display in the ne
<el-table-column
property="address"
label="Address"
show-tooltip-when-overflow>
show-overflow-tooltip>
</el-table-column>
</el-table>
</template>
......@@ -767,26 +774,34 @@ By default, if the content is too much, the extra content will display in the ne
export default {
data() {
return {
tableData3: [{
tableData3: [{
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-08',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-06',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-07',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}],
multipleSelection: []
}
......@@ -802,13 +817,11 @@ By default, if the content is too much, the extra content will display in the ne
```
:::
### Order
### Sorting
Sort the data to find or compare data quickly.
:::demo
Set attribute `sortable` to a certain column to sort the data
based on the column . It accepts the `Boolean` type with an default value `false`. In the example below we use attribute `formatter` to format the value of certain column. It accepts a function which has two parameters: `row` and `column`. You can handle it according to your own needs.
:::demo Set attribute `sortable` in a certain column to sort the data based on this column. It accepts `Boolean` with a default value `false`. In this example we use another attribute named `formatter` to format the value of certain columns. It accepts a function which has two parameters: `row` and `column`. You can handle it according to your own needs.
```html
<template>
<el-table
......@@ -816,18 +829,18 @@ based on the column . It accepts the `Boolean` type with an default value `false
border
style="width: 100%">
<el-table-column
property="date"
prop="date"
label="Date"
sortable
width="180">
</el-table-column>
<el-table-column
property="name"
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
property="address"
prop="address"
label="Address"
:formatter="formatter">
</el-table-column>
......@@ -840,30 +853,105 @@ based on the column . It accepts the `Boolean` type with an default value `false
return {
tableData: [{
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}]
}
},
methods: {
formatter(row, column) {
return row.address;
}
}
}
</script>
```
:::
### Filter
Filter the table to find desired data.
:::demo Set attribute `filters` and `filter-method` in `el-table-column` makes this column filterable. `filters` is an array, and `filter-method` is a function deciding which rows are displayed. It has two parameters: `value` and `row`.
```html
<template>
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
prop="date"
label="Date"
sortable
width="180">
</el-table-column>
<el-table-column
prop="name"
label="Name"
width="180">
</el-table-column>
<el-table-column
prop="address"
label="Address"
:formatter="formatter">
</el-table-column>
<el-table-column
prop="tag"
label="Tag"
width="100"
:filters="[{ text: 'Home', value: 'Home' }, { text: 'Office', value: 'Office' }]"
:filter-method="filterTag"
inline-template>
<el-tag :type="row.tag === 'Home' ? 'primary' : 'success'" close-transition>{{row.tag}}</el-tag>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-03',
name: 'Jack',
address: 'Putuo District of Shanghai Jinsha River Road 1518 Lane',
zip: 'CA 90036'
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
tag: 'Home'
}, {
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
tag: 'Office'
}, {
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
tag: 'Home'
}, {
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
tag: 'Office'
}]
}
},
methods: {
formatter(row, column) {
return row.address;
},
filterTag(value, row) {
return row.tag === value;
}
}
}
......@@ -872,40 +960,56 @@ based on the column . It accepts the `Boolean` type with an default value `false
:::
### Table Attributes
| Attribute | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| data | data to display | array | — | — |
| height | table 's height, default is null, meaning height is set automatically | string | — | — |
| stripe | whether stripe table or not| boolean | — | false |
| border | whether has border in vertical orientation or not | boolean | — | false |
| fit | whether width of column automatically distract or not | boolean | — | true |
| selection-mode | select mode | string | single/multiple/none | none |
| allow-no-selection | whether is allowed to be empty or not in Single Select | boolean | — | false |
| fixed-column-count | fixed columns counts | number | — | 0 |
| data | table data | array | — | — |
| height | table's height. By default | string/number | — | — |
| stripe | whether table is striped | boolean | — | false |
| border | whether table has vertical border | boolean | — | false |
| fit | whether width of column automatically fits its container | boolean | — | true |
| highlight-current-row | whether current row is highlighted | boolean | — | false |
| row-class-name | function that returns custom class names for a row | Function(row, index) | — | — |
| row-key | Key of row data, used for optimizing rendering. Required if `reserve-selection` is on | Function(row)/String | — | — |
### Table Events
| Event | Description | Paramters |
| Event Name | Description | Parameters |
| ---- | ---- | ---- |
| selectionchange | triggered when selection changes | selected |
| cellmouseenter | triggered when hovering on cell| row, column, cell, event |
| cellmouseleave | triggered when hovering leave cell | row, column, cell, event |
| cellclick | triggered when clicking cell| row, column, cell, event |
| select | triggers when user clicks the checkbox in a row | selection, row |
| select-all | triggers when user clicks the checkbox in table header | selection |
| selection-change | triggers when selection changes | selection |
| cell-mouse-enter | triggers when hovering into a cell| row, column, cell, event |
| cell-mouse-leave | triggers when hovering out of a cell | row, column, cell, event |
| cell-click | triggers when clicking a cell | row, column, cell, event |
| row-click | triggers when clicking a row | row, event |
| sort-change | triggers when Table's sorting changes | { column, prop, order } |
| current-change | triggers when current row changes | currentRow, oldCurrentRow |
### Table Methods
| Method | Description | Parameter |
|------|--------|-------|
| clearSelection | clear selection, might be useful when `reserve-selection` is on | selection |
| toggleRowSelection | toggle if a certain row is selected. With the second parameter, you can directly set if this row is selected | row, selected |
### Table-column Attributes
| Paramters | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| label | title | string | — | — |
| property | field name corresponding to the column name | string | — | — |
| type | type of the column. If set to `selection`, the column will display checkbox. If set to `index`, the column will display index of the row (staring from 1) | string | selection/index | — |
| label | column label | string | — | — |
| prop | field name. You can also use its alias: `property` | string | — | — |
| width | column width | string | — | — |
| sortable | whether can be sort or not | boolean | — | false |
| resizable | whether width of the column will change when dragged (If need it, you should set attribute `border` of `el-table` to true) ) | boolean | — | false |
| type | type of the column. If set to `selection`, the column will display checkbox. If set to `index`, the column will display index of the row (staring with 1) | string | selection/index | — |
| formatter | function that formats content, which has two parameters row and column | function | — | — |
| show-tooltip-when-overflow | if cell content is too long , the extra content will hide. Hovering on it the extra content will show in tooltip | Boolean | — | false |
| inline-template | when using the attribute, you could customize the content which the column. Refer to the date column in Multiple Select, getting row data by `row` object, getting current context by _self in JSX. In this case you don't need set the attribute `property`. | — | — |
| align | Alignment | String | left, center, right | left |
| min-width | column minimum width. Columns with `width` has a fixed width, while columns with `min-width` has a width that is distributed in proportion | string | — | — |
| fixed | whether column is fixed at left/right. Will be fixed at left if `true` | string/boolean | true/left/right | — |
| render-header | render function for table header of this column | Function(h, { column, $index }) | — | — |
| sortable | whether column can be sorted | boolean | — | false |
| sort-method | sorting method, works when `sortable` is `true` | Function(a, b) | — | — |
| resizable | whether column width can be resized, works when `border` of `el-table` is `true` | boolean | — | false |
| formatter | function that formats content | Function(row, column) | — | — |
| show-overflow-tooltip | whether to hide extra content and show them in a tooltip when hovering on the cell | boolean | — | false |
| inline-template | by using this attribute, you can customize column template. Row data can be accessed by `row` object, and current context can be accessed by `_self` in JSX. In this case you don't need to set `prop`. In your template, you have access to the following: `{ row (current row), column (current column), $index (row index), _self( context), store (table store) }` | — | — |
| align | alignment | string | left/center/right | left |
| selectable | function that determines if a certain row can be selected, works when `type` is 'selection' | Function(row, index) | — | — |
| reserve-selection | whether to reserve selection after data refreshing, works when `type` is 'selection' | boolean | — | false |
| filters | an array of data filtering options. For each element in this array, `text` and `value` are required | Array[{ text, value }] | — | — |
| filter-multiple | whether data filtering supports multiple options | Boolean | — | true |
| filter-method | data filtering method. If `filter-multiple` is on, this method will be called multiple times for each row, and a row will display if one of the calls returns `true` | Function(value, row) | — | — |
| filtered-value | filter value for selected data, might be useful when table header is rendered with `render-header` | Array | — | — |
<script>
export default {
data() {
return {
activeName: 'first',
tabs: [
{label: 'User', content: '', name: 'first'},
{label: 'Config', content: '', name: 'second'},
{label: 'Role', content: '', name: 'third'},
{label: 'Task', content: '', name: 'last'}
]
}
},
methods: {
handleRemove(tab) {
console.log(tab);
},
handleClick(tab, event) {
console.log(tab, event);
}
}
}
</script>
## Tabs
Divide data collections which have related contents however belong to different types.
Divide data collections which are related yet belong to different types.
### How to use
### Basic usage
Basic and concise tabs.
:::demo Tabs provide a selective card functionality and it can be achieved only by using `el-tabs` and child element `el-tab-pane`. In these two elements, we provide a list of attributes. The `label` in `el-tab-pane` determines the label of selective cards, you can write content in the label; In the next example, we add a `active-name` attribute in `el-tabs`, which can take a `String` value. It means an active card. In the `el-tab-pane` you can set corresponding `name` attribute,if there is no `name`, then the default sequence is `1`/`2`/`3`/`4`. In the example, the selected card is card 2. Since there's no `name`, then set `active-name` to `2` can reach the same goal.
:::demo Tabs provide a selective card functionality and it can be achieved by just using `el-tabs` and child element `el-tab-pane`. In these two elements, we provide a list of attributes. The `label` in `el-tab-pane` determines the label of selective cards, and you can write content in the label. In this example, we add a `active-name` attribute indicating the active card in `el-tabs`, which can take a `String` value. In the `el-tab-pane` you can set corresponding `name` attribute, and if there is no `name`, the default sequence is `1`/`2`/`3`/`4`. In this example, the selected card is card 2. If `name` is omitted, setting `active-name` to `2` can reach the same goal.
```html
<template>
<el-tabs>
<el-tab-pane label="User Admin"></el-tab-pane>
<el-tab-pane label="Config Admin"></el-tab-pane>
<el-tab-pane label="Role Admin"></el-tab-pane>
<el-tab-pane label="Task Compensation"></el-tab-pane>
</el-tabs>
<el-tabs :active-name="activeName">
<el-tab-pane v-for="tab in tabs" :label="tab.label" :name="tab.name">{{tab.content}}</el-tab-pane>
</el-tabs>
</template>
<script>
export default {
data() {
return {
activeName: 'first'
activeName: 'first',
tabs: [
{label: 'User', content: '', name: 'first'},
{label: 'Config', content: '', name: 'second'},
{label: 'Role', content: '', name: 'third'},
{label: 'Task', content: '', name: 'last'}
]
};
}
};
......@@ -31,17 +58,17 @@ Basic and concise tabs.
### Card Style
Selective card style tabs.
Tabs styled as cards.
:::demo Set `type` to `card` can get a selective card style tab.
:::demo Set `type` to `card` can get a card-styled tab.
```html
<template>
<el-tabs type="card" @tab-click="handleClick" @tab-remove="handleRemove">
<el-tab-pane label="User Admin"></el-tab-pane>
<el-tab-pane label="Config Admin"></el-tab-pane>
<el-tab-pane label="Role Admin"></el-tab-pane>
<el-tab-pane label="Task Compensation"></el-tab-pane>
<el-tab-pane label="User"></el-tab-pane>
<el-tab-pane label="Config"></el-tab-pane>
<el-tab-pane label="Role"></el-tab-pane>
<el-tab-pane label="Task"></el-tab-pane>
</el-tabs>
</template>
<script>
......@@ -50,8 +77,8 @@ Selective card style tabs.
handleRemove(tab) {
console.log(tab);
},
handleClick(tab) {
console.log(tab);
handleClick(tab, event) {
console.log(tab, event);
}
}
};
......@@ -63,15 +90,15 @@ Selective card style tabs.
Closable tabs.
:::demo You can set `closable` attribute in `el-tabs`.It accept `Boolean` and it will be closable when the boolean is `true`.
:::demo You can set `closable` attribute in `el-tabs`. It accept `Boolean` and Tab will be closable when the boolean is `true`.
```html
<template>
<el-tabs type="card" :closable="true" @tab-click="handleClick" @tab-remove="handleRemove">
<el-tab-pane label="User Admin"></el-tab-pane>
<el-tab-pane label="Config Admin"></el-tab-pane>
<el-tab-pane label="Role Admin"></el-tab-pane>
<el-tab-pane label="Task Compensation"></el-tab-pane>
<el-tab-pane label="User"></el-tab-pane>
<el-tab-pane label="Config"></el-tab-pane>
<el-tab-pane label="Role"></el-tab-pane>
<el-tab-pane label="Task"></el-tab-pane>
</el-tabs>
</template>
<script>
......@@ -80,8 +107,8 @@ Closable tabs.
handleRemove(tab) {
console.log(tab);
},
handleClick(tab) {
console.log(tab);
handleClick(tab, event) {
console.log(tab, event);
}
}
};
......@@ -98,32 +125,30 @@ Border card tabs.
```html
<el-tabs type="border-card">
<el-tab-pane label="User Admin"></el-tab-pane>
<el-tab-pane label="Config Admin"></el-tab-pane>
<el-tab-pane label="Role Admin"></el-tab-pane>
<el-tab-pane label="Task Compensation"></el-tab-pane>
<el-tab-pane label="User"></el-tab-pane>
<el-tab-pane label="Config"></el-tab-pane>
<el-tab-pane label="Role"></el-tab-pane>
<el-tab-pane label="Task"></el-tab-pane>
</el-tabs>
```
:::
### Tabs Attributes
| Attribute | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
| type | Tabs type | string | card, border-card | — |
| closable | If can close the tab | boolean | true, false | false |
| active-name | Name of the selected card | string | — | Name of first selective card |
| type | type of Tab | string | card/border-card | — |
| closable | whether Tab is closable | boolean | — | false |
| active-name | name of the selected tab | string | — | name of first tab |
### Tabs Events
| Event name | Description | Callback parameter |
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
| tab-click | Hook function when tab is clicked | Clicked tab |
| tab-remove | Hook function when tab is removed | Removed tab |
| tab-click | triggers when a tab is clicked | clicked tab |
| tab-remove | triggers when a tab is removed | removed tab |
### Tab-pane Attributes
| Attribute | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
| label | Card label | string | — | — |
| name | The identifier corresponding to the activeName of the selective card, representing the alias of the selective card | string | — | The ordinal number of the selective card in the sequence, i.e. the first one is '1' |
| label | title of the tab | string | — | — |
| name | identifier corresponding to the activeName of Tabs, representing the alias of the tab-pane | string | — | ordinal number of the tab-pane in the sequence, i.e. the first tab-pane is '1' |
......@@ -3,12 +3,12 @@
data() {
return {
tags: [
{ key: 1, name: 'Label one', type: '' },
{ key: 2, name: 'Label Two', type: 'gray' },
{ key: 5, name: 'Label Three', type: 'primary' },
{ key: 3, name: 'Label Four', type: 'success' },
{ key: 4, name: 'Label Five', type: 'warning' },
{ key: 6, name: 'Label Six', type: 'danger' }
{ key: 1, name: 'Tag one', type: '' },
{ key: 2, name: 'Tag Two', type: 'gray' },
{ key: 5, name: 'Tag Three', type: 'primary' },
{ key: 3, name: 'Tag Four', type: 'success' },
{ key: 4, name: 'Tag Five', type: 'warning' },
{ key: 6, name: 'Tag Six', type: 'danger' }
]
};
},
......@@ -32,23 +32,23 @@
Used for marking and selection.
### How to use
### Basic usage
::: demo It's defined by the `type` attribute, which is optional.
::: demo Use the `type` attribute to define Tag's type.
```html
<el-tag>Label One</el-tag>
<el-tag type="gray">Label Two</el-tag>
<el-tag type="primary">Label Three</el-tag>
<el-tag type="success">Label Four</el-tag>
<el-tag type="warning">Label Five</el-tag>
<el-tag type="danger">Label Six</el-tag>
<el-tag>Tag One</el-tag>
<el-tag type="gray">Tag Two</el-tag>
<el-tag type="primary">Tag Three</el-tag>
<el-tag type="success">Tag Four</el-tag>
<el-tag type="warning">Tag Five</el-tag>
<el-tag type="danger">Tag Six</el-tag>
```
:::
### Removable Label
### Removable Tag
:::demo Set the `closable` attribute to define a removeable tag, it can accepts a `Boolean` and you can set it with `true`. The removal of default label is accompanied by a gradient animation. If you don't want to use it, you can set the `close-transition` attribute, it accepts a `Boolean`, and will be turn off if set true. Setting the `close` event to handle the callback function after closing.
:::demo Set the `closable` attribute to define a removable tag. It accepts a `Boolean`. By default the removal of Tag has a fading animation. If you don't want to use it, you can set the `close-transition` attribute, which accepts a `Boolean`, to `true`. `close` event triggers when Tag is removed.
```html
<el-tag
......@@ -67,12 +67,12 @@ Used for marking and selection.
data() {
return {
tags: [
{ key: 1, name: 'Label One', type: '' },
{ key: 2, name: 'Label Two', type: 'gray' },
{ key: 5, name: 'Label Three', type: 'primary' },
{ key: 3, name: 'Label Four', type: 'success' },
{ key: 4, name: 'Label Five', type: 'warning' },
{ key: 6, name: 'Label Six', type: 'danger' }
{ key: 1, name: 'Tag One', type: '' },
{ key: 2, name: 'Tag Two', type: 'gray' },
{ key: 5, name: 'Tag Three', type: 'primary' },
{ key: 3, name: 'Tag Four', type: 'success' },
{ key: 4, name: 'Tag Five', type: 'warning' },
{ key: 6, name: 'Tag Six', type: 'danger' }
]
};
},
......@@ -87,15 +87,15 @@ Used for marking and selection.
:::
### Attributes
| Parameter | Description | Type | Options | Default |
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| type | theme | string | 'primary', 'gray', 'success', 'warning', 'danger' | — |
| closable | Whether it can be closed | boolean | — | false |
| close-transition | Whether gradient animation is disabled or not | boolean | — | false |
| hit | Is there a border stroke| boolean | — | false |
| type | theme | string | primary/gray/success/warning/danger | — |
| closable | whether Tab can be removed | boolean | — | false |
| close-transition | whether the removal animation is disabled | boolean | — | false |
| hit | whether Tag has a highlighted border | boolean | — | false |
### Events
| Event | Description | Callback |
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
| close | The event fired when the tab is closed | — |
\ No newline at end of file
| close | triggers when Tab is removed | — |
\ No newline at end of file
......@@ -9,7 +9,8 @@ npm i element-theme -D
安装默认主题,可以从 npm 安装或者从 GitHub 拉取最新代码。
```shell
npm i element-theme-default@next -D
# 从 npm
npm i element-theme-default -D
# 从 GitHub
npm i https://github.com/ElementUI/theme-default -D
......@@ -24,7 +25,7 @@ node_modules/.bin/et -i [可以自定义变量文件目录]
> ✔ Generator variables file
```
如果使用默认配置,执行后当前目录会有一个 `element-variables.css` 文件。内部包含了主题所用到所有变量,它们使用 CSS4 的风格定义。大致结构如下:
如果使用默认配置,执行后当前目录会有一个 `element-variables.css` 文件。内部包含了主题所用到所有变量,它们使用 CSS4 的风格定义。大致结构如下:
```css
:root {
......@@ -82,4 +83,4 @@ Vue.use(ElementUI)
}
```
如果不清楚 `babel-plugin-component` 是什么,请阅读 [快速上手](./examples/docs/zh-CN/quickstart.md) 一节。更多 `element-theme` 用法请参考[项目仓库](https://github.com/ElementUI/element-theme)
如果不清楚 `babel-plugin-component` 是什么,请阅读 <a href="./#/zh-CN/component/quickstart">快读上手</a> 一节。更多 `element-theme` 用法请参考[项目仓库](https://github.com/ElementUI/element-theme)
<style>
ul.language-list {
color: #5e6d82;
font-size: 14px;
padding-left: 20px;
li {
line-height: 1.8
}
}
</style>
## 国际化
Element 组件内部默认使用中文,若希望使用其他语言,则需要进行多语言设置。以英文为例,在 main.js 中:
......@@ -39,10 +49,12 @@ Vue.component(Select.name, Select)
}
```
目前 Element 内置了以下语言:
- 汉语
- 英语
- 德语
- 葡萄牙语
目前 Element 内置了以下语言:
<ul class="language-list">
<li>汉语(zh-CN)</li>
<li>英语(en)</li>
<li>德语(de)</li>
<li>葡萄牙语(pt)</li>
</ul>
如果你需要使用其他的语言,欢迎贡献 PR:只需在 [这里](https://github.com/ElemeFE/element/tree/master/src/locale/lang) 添加一个语言配置文件即可。
......@@ -12,9 +12,9 @@ npm i element-ui -D
```html
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui@1.0.0/lib/theme-default/index.css">
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui@1.0.0/lib/index.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
```
### Hello world
......@@ -26,7 +26,7 @@ npm i element-ui -D
<head>
<meta charset="UTF-8">
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui@1.0.0/lib/theme-default/index.css">
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
</head>
<body>
<div id="app">
......@@ -37,9 +37,9 @@ npm i element-ui -D
</div>
</body>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue@2.0.5/dist/vue.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui@1.0.0/lib/index.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
new Vue({
el: '#app',
......
......@@ -182,7 +182,7 @@ npm install babel-plugin-component -D
}
```
如果你只希望引入部分组件,比如 Button 和 Select,那么需要在 main.js 中写入以下内容:
接下来,如果你只希望引入部分组件,比如 Button 和 Select,那么需要在 main.js 中写入以下内容:
```javascript
import Vue from 'vue'
......@@ -202,47 +202,6 @@ new Vue({
})
```
### 多语言设置
Element 组件内部默认使用中文,若希望使用其他语言,则需要进行多语言设置。以英文为例,在 main.js 中:
```javascript
// 完整引入 Element
import Vue from 'vue'
import ElementUI from 'element-ui'
import locale from 'element-ui/lib/locale/lang/en'
Vue.use(ElementUI, { locale })
```
```javascript
// 按需引入 Element
import Vue from 'vue'
import { Button, Select } from 'element-ui'
import lang from 'element-ui/lib/locale/lang/en'
import locale from 'element-ui/lib/locale'
// 设置语言
locale.use(lang)
// 引入组件
Vue.component(Button.name, Button)
Vue.component(Select.name, Select)
```
如果使用其它语言,默认情况下中文语言包依旧是被引入的,可以使用 webpack 的 IgnorePlugin 忽略掉它以减少打包后的文件体积。
webpack.config.js
```javascript
{
plugins: [
new webpack.IgnorePlugin(/element-ui\/lib\/locale\/lang\/zh-CN/)
]
}
```
### 开始使用
至此,一个基于 Vue 和 Element 的开发环境已经搭建完毕,现在就可以编写代码了。启动开发模式:
......
......@@ -80,7 +80,7 @@
### 带图标的步骤条
步骤条内可以启用各种自定义的图标。
:::demo 通过`icon`属性来设置图标,图标的类型可以参考 Icon 组件的文档,除此以外,还能通过 slot name 来使用自定义的图标。
:::demo 通过`icon`属性来设置图标,图标的类型可以参考 Icon 组件的文档,除此以外,还能通过具名`slot`来使用自定义的图标。
```html
<el-steps :space="100" :active="1">
<el-step title="步骤 1" icon="edit"></el-step>
......
......@@ -75,4 +75,4 @@
### Events
| 事件名称 | 说明 | 回调参数 |
|---------- |-------- |---------- |
| change | switch 状态发生变化时的回调函数 | |
| change | switch 状态发生变化时的回调函数 | 新状态的布尔值 |
<script>
import Vue from 'vue';
export default {
data() {
return {
......@@ -328,7 +327,7 @@
可将表格内容 highlight 显示,方便区分「成功、信息、警告、危险」等内容。
:::demo 可以通过指定 Table 组件的 rowClassName 属性来为 Table 中的某一行添加 class,表明该行处于某种状态。
:::demo 可以通过指定 Table 组件的 `row-class-name` 属性来为 Table 中的某一行添加 class,表明该行处于某种状态。
```html
<template>
<el-table
......@@ -383,8 +382,7 @@
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
$info: true
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-01',
name: '王小虎',
......@@ -392,8 +390,7 @@
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
$positive: true
address: '上海市普陀区金沙江路 1518 弄'
}]
}
}
......@@ -969,13 +966,13 @@
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| data | 显示的数据 | array | — | — |
| height | table 的高度,默认高度为空,即自动高度,单位 px | string, number | — | — |
| height | table 的高度,默认高度为空,即自动高度,单位 px | string/number | — | — |
| stripe | 是否为斑马纹 table | boolean | — | false |
| border | 是否带有纵向边框 | boolean | — | false |
| fit | 列的宽度是否自撑开 | boolean | — | true |
| highlight-current-row | 是否要高亮当前行 | boolean | - | false |
| row-class-name | 行的 className 的回调。 | Function(row, index) | - | - |
| row-key | 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的 | Function(row), String | - | - |
| highlight-current-row | 是否要高亮当前行 | boolean | | false |
| row-class-name | 行的 className 的回调。 | Function(row, index) | — | — |
| row-key | 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的 | Function(row)/String | — | — |
### Table Events
| 事件名 | 说明 | 参数 |
......@@ -988,7 +985,7 @@
| cell-click | 当某个单元格被点击时会触发该事件 | row, column, cell, event |
| row-click | 当某一行被点击时会触发该事件 | row, event |
| sort-change | 当表格的排序条件发生变化的时候会触发该事件 | { column, prop, order } |
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | { column, prop, order } |
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | currentRow, oldCurrentRow |
### Table Methods
| 方法名 | 说明 | 参数 |
......@@ -1004,17 +1001,17 @@
| prop | 对应列内容的字段名,也可以使用 property 属性 | string | — | — |
| width | 对应列的宽度 | string | — | — |
| min-width | 对应列的最小宽度,与 width 的区别是 width 是固定的,min-width 会把剩余宽度按比例分配给设置了 min-width 的列 | string | — | — |
| fixed | 列是否固定在左侧或者右侧,true 表示固定在左侧 | string, boolean | true, left, right | - |
| render-header | 列标题 Label 区域渲染使用的 Function | Function(h, { column, $index }) | - | - |
| fixed | 列是否固定在左侧或者右侧,true 表示固定在左侧 | string, boolean | true, left, right | |
| render-header | 列标题 Label 区域渲染使用的 Function | Function(h, { column, $index }) | — | — |
| sortable | 对应列是否可以排序,如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件 | boolean, string | true, false, 'custom' | false |
| sort-method | 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效 | Function(a, b) | - | - |
| resizable | 对应列是否可以通过拖动改变宽度(如果需要在 el-table 上设置 border 属性为真) | boolean | — | true |
| sort-method | 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效 | Function(a, b) | — | — |
| resizable | 对应列是否可以通过拖动改变宽度(需要在 el-table 上设置 border 属性为真) | boolean | — | true |
| formatter | 用来格式化内容 | Function(row, column) | — | — |
| show-overflow-tooltip | 当过长被隐藏时显示 tooltip | Boolean | — | false |
| show-overflow-tooltip | 当内容过长被隐藏时显示 tooltip | Boolean | — | false |
| inline-template | 指定该属性后可以自定义 column 模板,参考多选的时间列,通过 row 获取行信息,JSX 里通过 _self 获取当前上下文。此时不需要配置 prop 属性。总共可以获取到 `{ row(当前行), column(当前列), $index(行数), _self(当前上下文), store(table store) }` 的信息。 | — | — |
| align | 对齐方式 | String | left, center, right | left |
| selectable | 仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选 | Function(row, index) | - | - |
| reserve-selection | 仅对 type=selection 的列有效,类型为 Boolean,为 true 则代表会保留之前数据的选项,需要配合 Table 的 clearSelection 方法使用。 | Boolean | - | false |
| selectable | 仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选 | Function(row, index) | — | — |
| reserve-selection | 仅对 type=selection 的列有效,类型为 Boolean,为 true 则代表会保留之前数据的选项,需要配合 Table 的 clearSelection 方法使用。 | Boolean | | false |
| filters | 数据过滤的选项,数组格式,数组中的元素需要有 text 和 value 属性。 | Array[{ text, value }] | — | — |
| filter-multiple | 数据过滤的选项是否多选 | Boolean | — | true |
| filter-method | 数据过滤使用的方法,如果是多选的筛选项,对每一条数据会执行多次,任意一次返回 true 就会显示。 | Function(value, row) | — | — |
......
......@@ -3,7 +3,6 @@
data() {
return {
activeName: 'first',
activeName2: '',
tabs: [
{label: '用户管理', content: '', name: 'first'},
{label: '配置管理', content: '', name: 'second'},
......@@ -41,6 +40,7 @@
export default {
data() {
return {
activeName: 'first',
tabs: [
{label: '用户管理', content: '', name: 'first'},
{label: '配置管理', content: '', name: 'second'},
......@@ -75,8 +75,8 @@
handleRemove(tab) {
console.log(tab);
},
handleClick(tab) {
console.log(tab);
handleClick(tab, event) {
console.log(tab, event);
}
}
};
......@@ -105,8 +105,8 @@
handleRemove(tab) {
console.log(tab);
},
handleClick(tab) {
console.log(tab);
handleClick(tab, event) {
console.log(tab, event);
}
}
};
......@@ -132,8 +132,8 @@
### Tabs Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------- |---------- |------------- |-------- |
| type | 风格类型 | string | card, border-card | — |
| closable | 标签是否可关闭 | boolean | true, false | false |
| type | 风格类型 | string | card/border-card | — |
| closable | 标签是否可关闭 | boolean | | false |
| active-name | 选中选项卡的 name | string | — | 第一个选项卡的 name |
### Tabs Events
......
......@@ -89,7 +89,7 @@
### Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| type | 主题 | string | 'primary', 'gray', 'success', 'warning', 'danger' | — |
| type | 主题 | string | primary/gray/success/warning/danger | — |
| closable | 是否可关闭 | boolean | — | false |
| close-transition | 是否禁用关闭时的渐变动画 | boolean | — | false |
| hit | 是否有边框描边 | boolean | — | false |
......
......@@ -14,10 +14,6 @@
border-radius: var(--tag-border-radius);
border: 1px solid var(--tag-border);
@when hit {
border-color: var(--tag-primary-color);
}
& .el-icon-close {
border-radius: 50%;
text-align: center;
......@@ -42,6 +38,9 @@
background-color: var(--tag-gray-fill);
border-color: var(--tag-gray-border);
color: var(--tag-gray-color);
@when hit {
border-color: var(--tag-gray-color);
}
& .el-tag__close:hover {
background-color: var(--tag-gray-color);
......@@ -52,6 +51,9 @@
background-color: var(--tag-primary-fill);
border-color: var(--tag-primary-border);
color: var(--tag-primary-color);
@when hit {
border-color: var(--tag-primary-color);
}
& .el-tag__close:hover {
background-color: var(--tag-primary-color);
......@@ -62,6 +64,9 @@
background-color: var(--tag-success-fill);
border-color: var(--tag-success-border);
color: var(--tag-success-color);
@when hit {
border-color: var(--tag-success-color);
}
& .el-tag__close:hover {
background-color: var(--tag-success-color);
......@@ -72,6 +77,9 @@
background-color: var(--tag-warning-fill);
border-color: var(--tag-warning-border);
color: var(--tag-warning-color);
@when hit {
border-color: var(--tag-warning-color);
}
& .el-tag__close:hover {
background-color: var(--tag-warning-color);
......@@ -82,6 +90,9 @@
background-color: var(--tag-danger-fill);
border-color: var(--tag-danger-border);
color: var(--tag-danger-color);
@when hit {
border-color: var(--tag-danger-color);
}
& .el-tag__close:hover {
background-color: var(--tag-danger-color);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment