WEB前端之ELEMENT-TABLE

3 篇文章 0 订阅
1 篇文章 0 订阅

1.使用左定位后样式错乱

在这里插入图片描述

解决方案:

为el-table添加max-height属性

 <el-table 
   :data="mangeData"
   :border="true"
   :stripe="true"
   ref="table"
   :style="bodyStyle"
   :max-height="bodyStyle.height"
   class="_el_table table-fixed"></el-table>

2.table列数据动态添加后样式错乱

在这里插入图片描述

解决方案

监听表格数据,使用doLayout方法

  watch: {
    'mangeData': {
      handler() {
        this.$nextTick(() => {
          this.$refs.table.doLayout()
        })
      },
      deep: true
    }
  }

3. 列宽固定,占不满table宽度,单元格拉伸导致页面布局错乱

请添加图片描述

解决方案

<template>
          <el-table :data="ol"
                    :border="true"
                    :stripe="true"
                    ref="table"
                    class="_el_table table-fixed"
                    @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="50px">
              </el-table-column>

              <el-table-column label="操作" width="120px" fixed="left">
                <template slot-scope="scope">
                    <el-button native-type="button"
                               type="danger"
                               plain>
                        删除
                    </el-button>
                </template>
              </el-table-column>

              <el-table-column label="机构名称" fixed="left" width="150px">
                <span slot-scope="scope">{{scope.row.manageName}}</span>
              </el-table-column>

              <el-table-column label="机构代码" fixed="left" width="100px">
                <span slot-scope="scope">{{scope.row.manageCode}}</span>
              </el-table-column>
              <el-table-column v-for="bank in tableBd" :key="bank.bankCode" :width="tableBd.length > colNumber ? '250px' : ''">
                <span slot="header" slot-scope="scope">{{bank.bankName}}</span>
                <template slot-scope="scope">
                    <span>{{tableText(scope.row[bank.bankCode])}}</span>
                </template>
              </el-table-column>
          </el-table>
</template>
<script>
export default {
  data() {
    return {
      ol: [],
      colNumber: 0
    }
  },
  mounted () {
    this.$nextTick(() => {
      const tableWidth = this.$refs.table.$el.offsetWidth
      this.colNumber = Math.floor((tableWidth - 50 - 120 - 150 - 100) / 250)
      window.addEventListener('resize', () => this.onResize())
    })
  },
  methods: {
    onResize() {
      this.$nextTick(() => {
        const tableWidth = this.$refs.table.$el.offsetWidth
        this.colNumber = Math.floor((tableWidth - 50 - 120 - 150 - 100) / 250)
      })
    }
  }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值