elementUi使用table表格设置表格宽度为rem
时间: 2023-09-28 11:06:12 浏览: 186
要将 Element UI 的表格宽度设置为 rem,你可以使用 CSS 的方式来实现。首先,将表格容器的宽度设置为 rem,然后将表格内部的每一列的宽度也设置为 rem。
下面是一个示例代码:
```html
<template>
<div class="table-container">
<el-table :data="tableData" style="width: rem;">
<el-table-column prop="name" label="Name" :width="getColumnWidth('name')"></el-table-column>
<el-table-column prop="age" label="Age" :width="getColumnWidth('age')"></el-table-column>
<!-- 其他列 -->
</el-table>
</div>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: 'John', age: 30 },
{ name: 'Jane', age: 25 },
// 其他数据
]
};
},
methods: {
getColumnWidth(columnName) {
// 根据你的需求计算每列的宽度,可以使用 rem 单位
// 返回一个字符串,例如 '10rem'
// 这里是一个示例,每列宽度都设置为 10rem
return '10rem';
}
}
};
</script>
<style>
.table-container {
width: rem;
}
</style>
```
请注意,在这个示例中,你需要根据自己的需求来计算每一列的宽度,然后将它们转换为符合 rem 单位的字符串。