首页 前端知识 vue3 el-table 表头以及表格文字居中

vue3 el-table 表头以及表格文字居中

2024-06-10 23:06:50 前端知识 前端哥 858 768 我要收藏

使表头文字居中:

:header-cell-style="{ textAlign: 'center' }"

表头嘛就多个header

使表格内容文字居中:

:cell-style="{ textAlign: 'center' }"

对比效果:

修改后代码:

<el-card class="table-all">
            <el-row>
                <el-table :data="userData" class="userList-table" :header-cell-style="{ textAlign: 'center' }"
                          :cell-style="{ textAlign: 'center' }">
                    <el-table-column prop="username" label="姓名"></el-table-column>
                    <el-table-column prop="password" label="密码"></el-table-column>
                    <el-table-column prop="phone" label="电话号码"></el-table-column>
                    <el-table-column prop="email" label="邮箱"></el-table-column>
                    <el-table-column prop="sex" label="性别"></el-table-column>
                    <el-table-column prop="age" label="年龄"></el-table-column>
                    <el-table-column label="头像">
                        <template #default="scope">
                            <el-image :src="require(`@/assets/img/${scope.row.avatar}`)" :alt="picture"
                                      style="width: 60px; height: 60px;"></el-image>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作">
                        <el-button type="primary" class="detail-btn">编辑</el-button>
                        <el-button type="danger" class="bigDelete-btn">删除</el-button>
                    </el-table-column>
                </el-table>
            </el-row>
            <el-row style="margin-left: 10%">
                <el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pagesize"
                               :total="userData.length">
                </el-pagination>
            </el-row>
        </el-card>

表头及表格内容未居中前:

表头及表格内容居中后:

是不是看起来更整齐了!

也可以通过:header-cell-style改其它格式,比如修改表头背景,表头高度:

:header-cell-style="{ textAlign: 'center' ,height: '70px', background: 'ghostwhite'} "


其它属性还有比如:

1、border:给表格加边框
2、height:可实现固定表头的表格,不需要额外的代码
3、fixed:接受 Boolean 值left或者 right,表示左边固定还是右边固定
4、show-overflow-tooltip:当内容过长被隐藏时显示 tooltip(文字提示)
5、row-class-name:改变某行的背景色


希望以上内容帮助到你!

转载请注明出处或者链接地址:https://www.qianduange.cn//article/11839.html
标签
学习方法
评论
发布的文章

FastJson 2『使用心得』

2024-06-18 23:06:34

fastjson(版本<=1.2.24)复现

2024-06-18 23:06:21

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!