当前位置:   article > 正文

element table展开行只显示一行_element-ui 表格只显示一行,点击查看更多

element-ui 表格只显示一行,点击查看更多

首先关键事件和属性

@expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys"

 expand-change 展开行change事件

 这里也只用第一个参数,

 expand-row-keys 绑定展开行的key值数组,设置为当前选择的key值就行

 row-key 辅助expand-row-keys的使用

 最终代码,亲测有效

  1. <template>
  2. <el-table ref="table" :data="tableData" @expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys">
  3. <el-table-column type="expand">
  4. <template>
  5. <el-table class="table-expand" :data="childTableData" >
  6. <el-table-column prop="category" label="z"></el-table-column>
  7. <el-table-column prop="address" label="x"></el-table-column>
  8. <el-table-column prop="shop" label="c"></el-table-column>
  9. <el-table-column prop="shopId" label="任务状态"></el-table-column>
  10. </el-table>
  11. </template>
  12. </el-table-column>
  13. <el-table-column label="Date" prop="date" />
  14. <el-table-column label="Name" prop="name" />
  15. </el-table>
  16. </template>
  17. <script lang="ts">
  18. export default {
  19. data() {
  20. return {
  21. tableData: [
  22. {
  23. id:1,
  24. date: '2016-05-03',
  25. name: 'Tom',
  26. state: 'California',
  27. city: 'Los Angeles',
  28. address: 'No. 189, Grove St, Los Angeles',
  29. zip: 'CA 90036',
  30. },
  31. {
  32. id:2,
  33. date: '2016-05-02',
  34. name: 'Tom',
  35. state: 'California',
  36. city: 'Los Angeles',
  37. address: 'No. 189, Grove St, Los Angeles',
  38. zip: 'CA 90036',
  39. },
  40. {
  41. id:3,
  42. date: '2016-05-04',
  43. name: 'Tom',
  44. state: 'California',
  45. city: 'Los Angeles',
  46. address: 'No. 189, Grove St, Los Angeles',
  47. zip: 'CA 90036',
  48. }
  49. ],
  50. expands:[2],
  51. getRowKeys(row) {
  52. return row.id
  53. },
  54. childTableData: [
  55. {
  56. category: "江浙小吃、小吃零食",
  57. address: "上海市普陀区真北路",
  58. shop: "王小虎夫妻店",
  59. shopId: "10333"
  60. }
  61. ],
  62. }
  63. },
  64. methods:{
  65. expandChange(row){
  66. this.expands = [row.id]
  67. }
  68. }
  69. }
  70. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/103255
推荐阅读
相关标签