Api
- Guidelines
- el-alert
- el-autocomplete
- el-breadcrumb
- el-button
- el-checkbox
- el-date-picker
- el-date-tiem-picker
- el-dialog
- el-dropdown
- el-form
- el-icon
- el-input-number
- el-input
- el-loading
- el-menu
- el-message-box
- el-notification
- el-pagination
- el-popover
- el-progress
- el-radio
- el-select
- el-slider
- el-switch
- el-table
- el-tabs
- el-tag
- el-time-picker
- el-tooltip
- el-tree
- el-upload
- Directives
- Filters
- Global Methods
- Cocoa App
- Instance Methods
- Instance Properties
el-table
基础表格
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <template> <el-table :data="tableData"> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }] } } } </script> |
带斑马纹表格
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <template> <el-table :data="tableData" stripe> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }] } } } </script> |
带边框表格
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <template> <el-table :data="tableData" border> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }] } } } </script> |
带状态表格
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <template> <el-table :data="tableData2"> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData2: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', $info: true }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', $positive: true }] } } } </script> |
固定表头
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <template> <el-table :data="tableData3" height="250" border> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData3: [{ date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-08', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-06', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-07', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }] } } } </script> |
固定列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <template> <el-table :data="tableData" :fixed-column-count="1" border style="width: 500px"> <el-table-column property="date" label="日期" width="150"></el-table-column> <el-table-column property="name" label="姓名" width="300"></el-table-column> <el-table-column property="address" label="地址" width="300"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }] } } } </script> |
固定列和表头
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <template> <el-table :data="tableData3" :fixed-column-count="1" border style="width: 500px" height="250"> <el-table-column property="date" label="日期" width="150"></el-table-column> <el-table-column property="name" label="姓名" width="300"></el-table-column> <el-table-column property="address" label="地址" width="300"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData3: [{ date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-08', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-06', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-07', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }] } } } </script> |
单选
“”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <template> <el-table :data="tableData" selection-mode="single" :selection.sync="singleSelection"> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }], singleSelection: {} } } } </script> |
多选
“”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <template> <el-table :data="tableData3" selection-mode="multiple" :selection.sync="multipleSelection"> <el-table-column type="selection" width="50"></el-table-column> <el-table-column property="date" label="日期" width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData3: [{ date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-08', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-06', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-07', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }], multipleSelection: [] } } } </script> |
排序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <template> <el-table :data="tableData" border style="width: 520px"> <el-table-column property="date" label="日期" sortable width="120"></el-table-column> <el-table-column property="name" label="姓名" width="120"></el-table-column> <el-table-column property="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }] } } } </script> |
el-table API
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| data | 显示的数据 | array | ||
| height | table 的高度,默认高度为空,即自动高度 | string | ‘’ | |
| stripe | 是否为斑马纹 table | boolean | false | |
| border | 是否带有纵向边框 | boolean | false | |
| selectionMode | 列表项选择模式 | string | ‘single’, ‘multiple’, ‘none’ | ‘none’ |
| allowNoSelection | 单选模式是否允许选项为空 | boolean | false | |
| selection | 多选模式下返回数组,单选模式下返回选中的元素。 | array/object | ||
| fixedColumnCount | 固定列的个数 | number | 0 |
el-table 事件
| 事件名 | 说明 | 参数 |
|---|---|---|
| selection-change | 当选择项发生变化时会触发该事件 | selected |
| cell-mouse-enter | 当单元格 hover 进入时会触发该事件 | row, column, cell, event |
| cell-mouse-leave | 当单元格 hover 退出时会触发该事件 | row, column, cell, event |
| cell-click | 当某个单元格被点击时会触发该事件 | row, column, cell, event |
el-table-column API
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| label | 显示的标题 | string | ‘’ | |
| property | 对应列内容的字段名 | string | ‘’ | |
| width | 对应列的宽度 | string | ||
| sortable | 对应列是否可以排序 | boolean | false | |
| type | 对应列的类型。如果设置了 selection 则显示多选按钮,如果设置了 index 则显示该行的索引(从 1 开始计算) |
string | ‘selection’, ‘index’ | 0 |
| formatter | 用来格式化内容,在 formatter 执行的时候,会传入 row 和 column | function |