el-table 固定表头

fixedTableHeaderMixin.js:

/*
    使用此mixin,需要在页面的el-table配置属性:ref="table" 和 :height="tableHeight"。
    举例:
    <el-table ref="table" :height="tableHeight" v-loading="tableLoading" element-loading-text="拼命加载中" :data="tableData" style="width: 99%">
 */
export default {
    data () {
        return {
            tableHeight: 250
        }
    },
    mounted () {
        this.$nextTick(() => {
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 115
            // 监听窗口大小变化
            window.onresize = () => {
                this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 115
            }
        })
    }
}

参考:https://www.cnblogs.com/muou2125/p/9952491.html

猜你喜欢

转载自www.cnblogs.com/cag2050/p/11882040.html