项目作者: yeyuqiudeng

项目描述 :
A vue table component that base on element ui.Just for using el-table component more convenient。 对element的table组件进行了封装,更方便地使用elment ui的el-table组件
高级语言: JavaScript
项目地址: git://github.com/yeyuqiudeng/vue-bel-table.git
创建时间: 2017-03-30T07:30:45Z
项目社区:https://github.com/yeyuqiudeng/vue-bel-table

开源协议:

下载


vue-bel-table

GitHub issues
GitHub forks
GitHub stars
Twitter

NPM

Description

A vue table component that base on element ui.Just for using el-table component more convenient。

对element的table组件进行了封装,更方便地使用elment ui的el-table组件

Dependency

Installation

  1. npm install vue-bel-table

Usage

  1. import BelTable from 'vue-bel-table'
  2. Vue.use(BelTable, options)

Options

  1. options: {
  2. table: Object, // 自定义table默认属性,必须为element ui支持的表格属性
  3. column: Object // 自定义列默认属性,必须为element ui支持的列属性
  4. }
  5. // 如果不传递,默认属性如下
  6. // 组件内的默认配置如下
  7. table: { // table的默认属性
  8. data: [],
  9. maxHeight: 600,
  10. border: true
  11. },
  12. column: { // column的默认属性
  13. showOverflowTooltip: true,
  14. headerAlign: 'center',
  15. resizable: true
  16. }

Props

  1. data: Array, // 表格的数据,1.1.0 新增,如果存在,configs中的attr的中可以不存在data属性
  2. configs: Object
  3. // configs的具体配置如下
  4. configs: {
  5. table: { // 表格配置
  6. default: {}, // 默认配置,配置属性要跟element ui的table attributes 一致,如果有配置,则忽略组件内defaultAttr的table默认配置
  7. attr: {} // 配置属性要跟element ui的table attributes一致
  8. },
  9. columnDefault: {}, // column的默认配置,要跟element ui的column attributes一致,如果有配置,则忽略defaultAttr的column默认配置
  10. columns: [ // column配置
  11. {
  12. attr: {}, // column的默认配置,要跟element的column attributes一致
  13. scopedSlot: '', // scope slot名称
  14. }
  15. ]
  16. }

events

跟element ui 的 events 一致

Table Methods

跟element ui 的table methods 一致

example

1.1.0后更推荐这样使用:

  1. <template>
  2. <bel-table
  3. ref="table"
  4. @row-click="toggleRowSelection"
  5. :data="tableData"
  6. :configs="tableConfig">
  7. <template slot="date" scope="scope">
  8. <span>{{scope.row.date}}</span>
  9. </template>
  10. </bel-table>
  11. </template>
  12. <script type="text/babel">
  13. export default {
  14. data () {
  15. return {
  16. tableData: [{
  17. date: '2016-05-02',
  18. name: '王小虎',
  19. address: '上海市普陀区金沙江路 1518 弄'
  20. }, {
  21. date: '2016-05-04',
  22. name: '王小虎',
  23. address: '上海市普陀区金沙江路 1517 弄'
  24. }, {
  25. date: '2016-05-01',
  26. name: '王小虎',
  27. address: '上海市普陀区金沙江路 1519 弄'
  28. }, {
  29. date: '2016-05-03',
  30. name: '王小虎',
  31. address: '上海市普陀区金沙江路 1516 弄'
  32. }],
  33. tableConfig: {
  34. get () {
  35. return {
  36. columns: [
  37. {
  38. attr: {
  39. type: 'selection',
  40. width: 80,
  41. align: 'center'
  42. }
  43. },
  44. {
  45. attr: {
  46. prop: 'date',
  47. label: '日期',
  48. minWidth: 180,
  49. scopedSlot: 'date',
  50. }
  51. },
  52. {
  53. attr: {
  54. prop: 'name',
  55. label: '姓名',
  56. minWidth: 180
  57. }
  58. },
  59. {
  60. attr: {
  61. prop: 'address',
  62. label: '地址',
  63. minWidth: 180
  64. }
  65. }
  66. ]
  67. }
  68. }
  69. }
  70. }
  71. },
  72. methods: {
  73. toggleRowSelection (row) {
  74. this.$refs.table.toggleRowSelection(row)
  75. }
  76. }
  77. }
  78. </script>

1.1.0以前的使用方式,1.1.0以后的版本同样兼容

  1. <template>
  2. <bel-table
  3. ref="table"
  4. @row-click="toggleRowSelection"
  5. :configs="tableConfig">
  6. <template slot="date" scope="scope">
  7. <span>{{scope.row.date}}</span>
  8. </template>
  9. </bel-table>
  10. </template>
  11. <script type="text/babel">
  12. export default {
  13. data () {
  14. return {
  15. tableData: [{
  16. date: '2016-05-02',
  17. name: '王小虎',
  18. address: '上海市普陀区金沙江路 1518 弄'
  19. }, {
  20. date: '2016-05-04',
  21. name: '王小虎',
  22. address: '上海市普陀区金沙江路 1517 弄'
  23. }, {
  24. date: '2016-05-01',
  25. name: '王小虎',
  26. address: '上海市普陀区金沙江路 1519 弄'
  27. }, {
  28. date: '2016-05-03',
  29. name: '王小虎',
  30. address: '上海市普陀区金沙江路 1516 弄'
  31. }]
  32. }
  33. },
  34. computed: {
  35. tableConfig: {
  36. get () {
  37. return {
  38. table: {
  39. attr: {
  40. data: this.tableData
  41. }
  42. },
  43. columns: [
  44. {
  45. attr: {
  46. type: 'selection',
  47. width: 80,
  48. align: 'center'
  49. }
  50. },
  51. {
  52. attr: {
  53. prop: 'date',
  54. label: '日期',
  55. minWidth: 180,
  56. scopedSlot: 'date',
  57. }
  58. },
  59. {
  60. attr: {
  61. prop: 'name',
  62. label: '姓名',
  63. minWidth: 180
  64. }
  65. },
  66. {
  67. attr: {
  68. prop: 'address',
  69. label: '地址',
  70. minWidth: 180
  71. }
  72. }
  73. ]
  74. }
  75. }
  76. }
  77. },
  78. methods: {
  79. toggleRowSelection (row) {
  80. this.$refs.table.toggleRowSelection(row)
  81. }
  82. }
  83. }
  84. </script>