• el-table固定表头(设置height)出现内容过多时不能滚动问题


    主要原因是el-table没有div包裹

    解决:加一个div并设置其高度和overflow

    我自己的主要代码

    1. <div class="contentTable">
    2. <el-table
    3. ref="table"
    4. :data="tableData"
    5. stripe
    6. @row-dblclick="onRowDblclick"
    7. height="100%"
    8. >
    9. <el-table-column
    10. type="index"
    11. align="center"
    12. label="序号"
    13. width="50"
    14. >el-table-column>
    15. <el-table-column
    16. prop="templateName"
    17. align="center"
    18. label="模板名称"
    19. width="150"
    20. >el-table-column>
    21. <el-table-column
    22. prop="mainContent"
    23. align="center"
    24. label="主要内容"
    25. >el-table-column>
    26. <el-table-column
    27. prop="devContent"
    28. align="center"
    29. label="活动措施和设备状态"
    30. >el-table-column>
    31. <el-table-column prop="operate" align="center" label="操作" width="80">
    32. <template slot-scope="scope">
    33. <el-button
    34. size="mini"
    35. class="delete-btn"
    36. @click="onDelete(scope.row)"
    37. title="删除"
    38. v-isLogin
    39. >el-button>
    40. template>
    41. el-table-column>
    42. el-table>
    43. div>

    css代码:

    1. .contentTable {
    2. height: calc(100% - 50px) !important;
    3. overflow: scroll;
    4. }
    5. .contentTable >>> .el-table__body-wrapper::-webkit-scrollbar {
    6. width: 10px;
    7. height: 8px;
    8. }

    -webkit-scrollbar用来加滚动条的!!!

    页面所有代码:

    1. <script>
    2. import { listTemplatesByType } from "@/api/template.js";
    3. import { removeTemplate } from "@/api/template.js";
    4. import { getBizcodeList } from "@/api/common.js";
    5. export default {
    6. props: {
    7. templateQueryVisible: {
    8. type: Boolean,
    9. default: false,
    10. },
    11. type: {
    12. type: String,
    13. default: "",
    14. },
    15. typeName: {
    16. type: String,
    17. default: "",
    18. },
    19. },
    20. data() {
    21. return {
    22. title: "",
    23. form: {
    24. templateName: "",
    25. },
    26. headField: [], //表头信息
    27. tableData: [], //表格数据
    28. };
    29. },
    30. computed: {
    31. visible: {
    32. get() {
    33. return this.templateQueryVisible;
    34. },
    35. set(val) {
    36. this.$emit("update:templateQueryVisible", val);
    37. },
    38. },
    39. },
    40. mounted() {},
    41. methods: {
    42. //打开窗口初始化
    43. openInit() {
    44. this.title = this.typeName + "模板管理";
    45. this.form.templateName = "";
    46. //根据type查询表头信息
    47. // listGridHeadByType({ type: this.type }).then(async (res) => {
    48. // var headFieldList = JSON.parse(res.data.data);
    49. // for (var i = 0; i < headFieldList.length; i++) {
    50. // if ("codeType" in headFieldList[i]) {
    51. // await getBizcodeList(headFieldList[i].codeType).then((res) => {
    52. // headFieldList[i]["codeList"] = res.data.data;
    53. // });
    54. // }
    55. // }
    56. // this.headField = headFieldList;
    57. // });
    58. //查询模板数据
    59. this.onQuery();
    60. },
    61. //删除
    62. onDelete(row) {
    63. var that = this;
    64. this.$confirm("确定删除该模板?", "提示", {
    65. confirmButtonText: "确定",
    66. cancelButtonText: "取消",
    67. type: "warning",
    68. }).then(() => {
    69. removeTemplate(row.id).then((res) => {
    70. if (res.data.code == "1") {
    71. that.$message({
    72. type: "success",
    73. message: "删除模板成功!",
    74. });
    75. that.onQuery();
    76. } else {
    77. that.$message({
    78. type: "error",
    79. message: "保存模板失败!",
    80. });
    81. }
    82. });
    83. });
    84. },
    85. //双击行加载模板数据
    86. onRowDblclick(row) {
    87. if (row.id) {
    88. delete row.id;
    89. }
    90. if (row.ID) {
    91. delete row.ID;
    92. }
    93. this.$emit("loadTemplateData", row);
    94. },
    95. //查询
    96. onQuery() {
    97. //根据type查询模板数据
    98. listTemplatesByType({
    99. type: this.type,
    100. name: this.form.templateName,
    101. }).then((res) => {
    102. var resData = res.data.data;
    103. var tableData = [];
    104. console.log(resData);
    105. if (resData) {
    106. for (var i = 0; i < resData.length; i++) {
    107. var content = JSON.parse(resData[i].content);
    108. let res = {
    109. id: resData[i].id,
    110. templateName: resData[i].name,
    111. mainContent: content.mainContent,
    112. devContent: content.devContent,
    113. };
    114. tableData.push(res);
    115. }
    116. this.tableData = tableData;
    117. } else {
    118. this.tableData = [];
    119. }
    120. });
    121. },
    122. //重置
    123. onReset() {
    124. if (this.$refs.form) {
    125. this.$refs.form.resetFields();
    126. this.onQuery();
    127. }
    128. },
    129. //渲染表格列
    130. itemFormatter(cellValue, codeList) {
    131. if (codeList && cellValue) {
    132. // return this.$common.renderCodeId(cellValue, codeList);
    133. return this.$common.renderCode(cellValue, "ID", "TEXT", codeList);
    134. } else {
    135. return cellValue;
    136. }
    137. },
    138. },
    139. };
    140. script>
    141. <style scoped>
    142. .template-query >>> .el-dialog__body {
    143. height: 600px;
    144. }
    145. .template-query >>> .el-form-item__label {
    146. width: 85px !important;
    147. }
    148. .delete-btn {
    149. background-image: url("~@/assets/imgs/delete.png");
    150. width: 23px;
    151. height: 23px;
    152. padding-left: 5px;
    153. cursor: pointer;
    154. background-repeat: no-repeat;
    155. }
    156. .contentTable {
    157. height: calc(100% - 50px) !important;
    158. overflow: scroll;
    159. }
    160. .contentTable >>> .el-table__body-wrapper::-webkit-scrollbar {
    161. width: 10px;
    162. height: 8px;
    163. }
    164. style>

  • 相关阅读:
    【大数据】一、大数据环境配置
    软件评测师之逻辑运算
    精读《深度学习 - 函数式之美》
    Mongodb字段更新操作符$currentDate
    AutoSAR点亮LED:开发环境介绍
    asp.net毕业设计项目源码社区保障管理系统
    css第十一课:浮动属性
    毕业设计:SpringBoot+Vue+Element的校内跑腿平台
    将Eureka服务注册到Eureka中心
    小白系统初始化配置资源失败怎么办
  • 原文地址:https://blog.csdn.net/qq_42192641/article/details/134457340