• vue项目实现table表格竖向


    先上图

    思路:使用element ui 自带的栅格,通过控制el-col 的span 属性来设置每行展示多少行(竖着的字段),超过就自动换行;

    content1 是表头

    content2是返回的数据

    getTable()函数是将返回的正常数据进行处理,和表格字段相对应

    表格样式在代码中有注释

    代码:

    1. <template>
    2. <div>
    3. <el-drawer
    4. title="对比"
    5. :visible.sync="drawer"
    6. :direction="direction"
    7. :before-close="handleClose"
    8. size="1000px"
    9. >
    10. <div style="margin:31px;">
    11. <div style="height:408px;overflow-x: auto;overflow-y: hidden;">
    12. <el-col :span="howWidth" v-for="(item, index) in columns" :key="index">
    13. <div class="box">
    14. <div class="content1">
    15. <div style="width:130px">{{ item.label }}</div>
    16. </div>
    17. <div v-for="(itC,itN) in item.value" :key="itN" class="content2">
    18. <div
    19. :title=" itC.length > 8 ?itC:''"
    20. >{{ itC.length > 8 ? itC.slice(0,8)+'...' : itC }}</div>
    21. </div>
    22. </div>
    23. </el-col>
    24. </div>
    25. </div>
    26. </el-drawer>
    27. </div>
    28. </template>
    29. <script>
    30. export default {
    31. data() {
    32. return {
    33. drawer: false,
    34. direction: "rtl",
    35. howWidth: 13,
    36. columns: [
    37. {
    38. prop: "gunName",
    39. label: "电枪名称",
    40. width: "200"
    41. },
    42. {
    43. prop: "gunMeter",
    44. label: "电表当前读数",
    45. width: "200"
    46. },
    47. {
    48. prop: "gunOutVolt",
    49. label: "电表输出电压",
    50. width: "200"
    51. },
    52. {
    53. prop: "gunOutElec",
    54. label: "电表输出电流",
    55. width: "200"
    56. },
    57. {
    58. prop: "gunCharged",
    59. label: "已充电量",
    60. width: "200"
    61. },
    62. {
    63. prop: "gunNeedVolt",
    64. label: "需求电压",
    65. width: "200"
    66. },
    67. {
    68. prop: "gunNeedElec",
    69. label: "需求电流",
    70. width: "200"
    71. },
    72. {
    73. prop: "gunSurveyVolt",
    74. label: "测量电压",
    75. width: "200"
    76. },
    77. {
    78. prop: "gunBtrVolt",
    79. label: "电池电压",
    80. width: "200"
    81. },
    82. {
    83. prop: "gunBtrElec",
    84. label: "电池电流",
    85. width: "200"
    86. }
    87. ]
    88. };
    89. },
    90. methods: {
    91. open() {
    92. this.drawer = true;
    93. this.getTable();
    94. },
    95. getTable() {
    96. let tableData = [
    97. {
    98. gunName: "1",
    99. gunMeter: "枪号",
    100. gunOutVolt: "bb",
    101. gunOutElec: "tt",
    102. gunCharged: "xxxx",
    103. gunNeedVolt: "cccc",
    104. gunNeedElec: "111111111111111111111",
    105. gunSurveyVolt: "1111111",
    106. gunBtrVolt: "1111111",
    107. gunBtrElec: "1111111"
    108. },
    109. {
    110. gunName: "2",
    111. gunMeter: "枪号",
    112. gunOutVolt: "bb",
    113. gunOutElec: "tt",
    114. gunCharged: "xxxx",
    115. gunNeedVolt: "cccc",
    116. gunNeedElec: "1111111",
    117. gunSurveyVolt: "1111111",
    118. gunBtrVolt: "1111111",
    119. gunBtrElec: "1111111"
    120. },
    121. {
    122. gunName: "3",
    123. gunMeter: "枪号",
    124. gunOutVolt: "bb",
    125. gunOutElec: "tt",
    126. gunCharged: "xxxx",
    127. gunNeedVolt: "cccc",
    128. gunNeedElec: "1111111",
    129. gunSurveyVolt: "1111111",
    130. gunBtrVolt: "1111111",
    131. gunBtrElec: "1111111"
    132. },
    133. {
    134. gunName: "4",
    135. gunMeter: "枪号",
    136. gunOutVolt: "bb",
    137. gunOutElec: "tt",
    138. gunCharged: "xxxx",
    139. gunNeedVolt: "cccc",
    140. gunNeedElec: "1111111",
    141. gunSurveyVolt: "1111111",
    142. gunBtrVolt: "1111111",
    143. gunBtrElec: "1111111"
    144. },
    145. {
    146. gunName: "5",
    147. gunMeter: "枪号",
    148. gunOutVolt: "bb",
    149. gunOutElec: "tt",
    150. gunCharged: "xxxx",
    151. gunNeedVolt: "cccc",
    152. gunNeedElec: "1111111",
    153. gunSurveyVolt: "1111111",
    154. gunBtrVolt: "1111111",
    155. gunBtrElec: "1111111"
    156. },
    157. {
    158. gunName: "6",
    159. gunMeter: "枪号",
    160. gunOutVolt: "bb",
    161. gunOutElec: "tt",
    162. gunCharged: "xxxx",
    163. gunNeedVolt: "cccc",
    164. gunNeedElec: "1111111",
    165. gunSurveyVolt: "1111111",
    166. gunBtrVolt: "1111111",
    167. gunBtrElec: "1111111"
    168. },
    169. {
    170. gunName: "7",
    171. gunMeter: "枪号",
    172. gunOutVolt: "bb",
    173. gunOutElec: "tt",
    174. gunCharged: "xxxx",
    175. gunNeedVolt: "cccc",
    176. gunNeedElec: "1111111",
    177. gunSurveyVolt: "1111111",
    178. gunBtrVolt: "1111111",
    179. gunBtrElec: "1111111"
    180. },
    181. {
    182. gunName: "8",
    183. gunMeter: "枪号",
    184. gunOutVolt: "bb",
    185. gunOutElec: "tt",
    186. gunCharged: "xxxx",
    187. gunNeedVolt: "cccc",
    188. gunNeedElec: "1111111",
    189. gunSurveyVolt: "1111111",
    190. gunBtrVolt: "1111111",
    191. gunBtrElec: "1111111"
    192. },
    193. {
    194. gunName: "9",
    195. gunMeter: "枪号",
    196. gunOutVolt: "bb",
    197. gunOutElec: "tt",
    198. gunCharged: "xxxx",
    199. gunNeedVolt: "cccc",
    200. gunNeedElec: "1111111",
    201. gunSurveyVolt: "1111111",
    202. gunBtrVolt: "1111111",
    203. gunBtrElec: "1111111"
    204. },
    205. {
    206. gunName: "10",
    207. gunMeter: "枪号",
    208. gunOutVolt: "bb",
    209. gunOutElec: "tt",
    210. gunCharged: "xxxx",
    211. gunNeedVolt: "cccc",
    212. gunNeedElec: "1111111",
    213. gunSurveyVolt: "1111111",
    214. gunBtrVolt: "1111111",
    215. gunBtrElec: "1111111"
    216. }
    217. ];
    218. this.columns.forEach(item => {
    219. item.value = [];
    220. for (let i in tableData) {
    221. for (let j in tableData[i]) {
    222. console.log("j", j);
    223. if (item.prop == j) {
    224. item.value.push(tableData[i][j]);
    225. }
    226. }
    227. }
    228. });
    229. console.log("this.columns[item]", this.columns);
    230. },
    231. handleClose() {
    232. this.drawer = false;
    233. }
    234. }
    235. };
    236. </script>
    237. <style lang="less" scoped>
    238. .box {
    239. width: 100%;
    240. height: 40px;
    241. display: flex;
    242. .content1 {
    243. width: 130px;
    244. height: 40px;
    245. line-height: 40px;
    246. text-align: center;
    247. background-color: #e7f2fd;
    248. border-right: 1px solid #e9e9e9;
    249. border-bottom: 1px solid #e9e9e9;
    250. border-left: 1px solid #409eff;
    251. color: #252525;
    252. font-size: 14px;
    253. font-weight: 700;
    254. position: absolute; //表头固定
    255. }
    256. .content2:nth-child(odd) { //对奇数列样式进行设置
    257. min-width: 200px;
    258. height: 40px;
    259. line-height: 40px;
    260. text-align: center;
    261. background: #f4f8fc;
    262. color: #666666;
    263. border-right: 1px solid #e9e9e9;
    264. border-bottom: 1px solid #e9e9e9;
    265. font-size: 14px;
    266. }
    267. .content2:nth-child(2) {
    268. margin-left: 130px !important; //表头固定后,数据内容的第一列需要设置左边距空出表头的宽度
    269. }
    270. .content2:nth-child(even) { //对偶数列样式进行设置
    271. min-width: 200px;
    272. height: 40px;
    273. line-height: 40px;
    274. text-align: center;
    275. background: #fff;
    276. color: #666666;
    277. border-right: 1px solid #e9e9e9;
    278. border-bottom: 1px solid #e9e9e9;
    279. font-size: 14px;
    280. }
    281. }
    282. </style>

  • 相关阅读:
    Python 实现Excel自动化办公(中)
    绿色便携方式安装apache+mysql+tomcat+php集成环境并提供控制面板
    webpack splitChunks解析
    算法-次数差
    GStreamer在Linux平台的交叉编译
    StableAudio-大模型创作音乐的工具
    通达OA RCE远程代码执行漏洞分析
    【并发】Java并发线程池底层原理详解与源码分析(下)
    NativeBuferring,一种零分配的数据类型[上篇]
    vue3 新特性(defineOptions defineModel)
  • 原文地址:https://blog.csdn.net/weixin_46041322/article/details/132847139