018:vue中自定义el-table 表头和单元格的样式

梦里梦外; 2024-03-16 19:41 91阅读 0赞

在这里插入图片描述

第018个

el-table 用于展示多条结构类似的数据,可对数据进行排序、筛选、对比或其他自定义操作。 vue在使用element UI table的是经常要用到的,由于原有的表头和单元格的样式不能满足项目的需要,需要自己来自定义样式。同时这里也做了个overflow-y的设置,让更多的内容在滚动条滑动下展示。

文章目录

    • 示例效果图
    • 示例源代码(共78行)
    • 核心代码

示例效果图

在这里插入图片描述

示例源代码(共78行)

  1. /*
  2. * @Author: 大剑师兰特(xiaozhuanlan),还是大剑师兰特(CSDN)
  3. * @此源代码版权归大剑师兰特所有,可供学习或商业项目中借鉴,未经授权,不得重复地发表到博客、论坛,问答,git等公共空间或网站中。
  4. * @Email: 2909222303@qq.com
  5. * @weixin: gis-dajianshi
  6. * @First published in CSDN
  7. * @First published time: 2022-06-17
  8. */
  9. <template>
  10. <div class="container">
  11. <h3>vue+element UI:自定义el-table 表头和表格的样式 </h3>
  12. <div class="author">大剑师兰特, 还是大剑师兰特,gis-dajianshi</div>
  13. <el-table :data="tableData" style="width: 100%;border: 1px solid #DDE1E6 ;border-radius: 4px;" height="380"
  14. :header-cell-style="{ background: '#abf',color: '#404A53', padding: '0px 0px', textAlign: 'left',}"
  15. :cell-style="{ padding: '8px 10px 8px 0', textAlign: 'left' }"
  16. >
  17. <el-table-column prop="title" label="图片" width="180">
  18. <template slot-scope="scope">
  19. <el-image :src="scope.row.thumbnail_pic_s"></el-image>
  20. </template>
  21. </el-table-column>
  22. <el-table-column prop="date" label="日期" width="180">
  23. </el-table-column>
  24. <el-table-column prop="title" label="标题" >
  25. <template slot-scope="scope">
  26. <div>
  27. <span>{
  28. {
  29. scope.row.title}}</span>
  30. </div>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. </div>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. tableData: [],
  41. }
  42. },
  43. mounted() {
  44. this.getdata()
  45. },
  46. methods: {
  47. getdata() {
  48. let url = "/listdata"
  49. this.$request(url, {
  50. }, "GET")
  51. .then((res) => {
  52. this.tableData = res.data.data
  53. console.log(this.tableData)
  54. })
  55. },
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. .container {
  61. width: 840px;
  62. height: 500px;
  63. margin: 50px auto;
  64. border: 2px solid orange;
  65. padding:5px 10px;
  66. }
  67. .author {
  68. line-height: 30px;
  69. color:#666;
  70. margin-bottom: 20px;
  71. background:#FDF5E6;
  72. font-size: 14px;
  73. }
  74. </style>

核心代码

表头:
:header-cell-style=“{ background: ‘#abf’,color: ‘#404A53’, padding: ‘0px 0px’, textAlign: ‘left’,}”

单元格:
:cell-style=”{ padding: ‘8px 10px 8px 0’, textAlign: ‘left’ }

表格高度,超过部分滚动处理
height=“380”

发表评论

表情:
评论列表 (有 0 条评论,91人围观)

还没有评论,来说两句吧...

相关阅读