当前位置:   article > 正文

Vue + Element实现表格嵌套表格_element中table中包含table

element中table中包含table
  1. <template>
  2. <div class="shopList">
  3. <el-table :data="tableData" style="width: 100%">
  4. <el-table-column type="expand">
  5. <template slot-scope="props">
  6. <el-table
  7. :data="props.row.sonData"
  8. style="width: 100%;padding: 10px;"
  9. >
  10. <el-table-column
  11. v-for="(value, id, index) in sonColumns"
  12. :label="value.name"
  13. :prop="value.propName"
  14. :key="index"
  15. >
  16. </el-table-column>
  17. <el-table-column label="操作">
  18. <template slot-scope="scope">
  19. <el-button
  20. :type="primary"
  21. @click="changeStatus()"
  22. >{{
  23. props.row.status ? "完成" : "修改"
  24. }}</el-button
  25. >
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. </template>
  30. </el-table-column>
  31. //对外层的表格表头进行了遍历循环
  32. <el-table-column
  33. v-for="(value, key, index) in parentsCloums"
  34. :label="value.name"
  35. :prop="value.propName"
  36. :key="index"
  37. >
  38. </el-table-column>
  39. </el-table>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. name: "shopList",
  45. components: {},
  46. data() {
  47. return {
  48. parentsCloums: [
  49. //外层table的表头
  50. // 最外层table的表头数据
  51. {
  52. name: "序号序号",
  53. id: "1",
  54. propName: "index"
  55. },
  56. {
  57. name: "商品类型商品类型",
  58. id: "2",
  59. propName: "type"
  60. },
  61. {
  62. name: "商品编号商品编号",
  63. id: "3",
  64. propName: "no"
  65. },
  66. {
  67. name: "商品名称商品名称",
  68. id: "4",
  69. propName: "spname"
  70. },
  71. {
  72. name: "食材食材",
  73. id: "5",
  74. propName: "shicai"
  75. },
  76. {
  77. name: "商品价格商品价格",
  78. id: "6",
  79. propName: "price"
  80. },
  81. {
  82. name: "商品图片商品图片",
  83. id: "7",
  84. propName: "pic"
  85. },
  86. {
  87. name: "当前库存当前库存",
  88. id: "8",
  89. propName: "kucun"
  90. },
  91. {
  92. name: "创建时间创建时间",
  93. id: "9",
  94. propName: "time"
  95. }
  96. ],
  97. tableData: [
  98. //外层table的数据
  99. // 最外层table数据,里面的sonData为嵌套表格的数据
  100. {
  101. id: 1,
  102. index: "1",
  103. type: "蛋糕蛋糕",
  104. no: "2315436",
  105. spname: "草莓甜心草莓甜心",
  106. shicai: "草莓莓,奶油油,蛋糕糕",
  107. price: "¥33.00",
  108. pic: "10333",
  109. kucun: "100",
  110. time: "2022-09-08 12:00:00",
  111. sonData: [
  112. //把要嵌套的内层table数据,放在父级table的一个字段里
  113. {
  114. index: "1",
  115. rkTime: "2022-09-08 12:00:00",
  116. rkNum: "50",
  117. operation: ""
  118. },
  119. {
  120. index: "1",
  121. rkTime: "2022-09-08 12:00:00",
  122. rkNum: "50",
  123. operation: ""
  124. }
  125. ]
  126. },
  127. {
  128. id: 2,
  129. index: "2",
  130. type: "蛋糕蛋糕",
  131. no: "2315436",
  132. spname: "草莓甜心草莓甜心",
  133. shicai: "草莓莓,奶油莓,蛋糕莓",
  134. price: "¥33.00",
  135. pic: "10333",
  136. kucun: "100",
  137. time: "2022-09-08 12:00:00"
  138. },
  139. {
  140. id: 3,
  141. index: "3",
  142. type: "蛋糕莓",
  143. no: "2315436",
  144. spname: "草莓甜心莓",
  145. shicai: "草莓莓,奶油莓,蛋糕莓",
  146. price: "¥33.00",
  147. pic: "10333",
  148. kucun: "100",
  149. time: "2022-09-08 12:00:00"
  150. }
  151. ],
  152. sonColumns: [
  153. //内层table的表头
  154. // 嵌套内层表格的表头
  155. {
  156. name: "序号序号",
  157. id: "1",
  158. propName: "index"
  159. },
  160. {
  161. name: "入库时间时间",
  162. id: "2",
  163. propName: "rkTime"
  164. },
  165. {
  166. name: "入库数量数量",
  167. id: "3",
  168. propName: "rkNum"
  169. }
  170. ]
  171. };
  172. },
  173. methods: {}
  174. };
  175. </script>
  176. <style scoped></style>

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

闽ICP备14008679号