element-plus的表头和数据行错位

576 阅读1分钟

问题 表头和下面的数据行明显错位了。表头靠左,数据行是居中。

image.png

在网上找的都是类似的答案, 试了其中一个doLayout的,不行。

在表头加ref

    <el-table
        :data="tableData"
        style="width: 100%"
        border
        ref="feedbackTable"
    >

然后监听数据源,如果有数据变化则重新布局。

    watch: {
        "tableData":{
            handler(val, oldVal){
                // console.log("tableData", val, oldVal)
                this.$nextTick(()=>{
                    console.log("nextTick", this.$refs.feedbackTable)
                    this.$refs.feedbackTable.doLayout()
                })
            },
        }
    }

解决方法

前面分析是表头靠左, 数据行居中, 那么试一下让整个表格居中 ,增加了align="center",问题完美解决

    <el-table
        :data="tableData"
        style="width: 100%"
        border
        align="center"
    >

image.png