在Vue的el-table中,可以使用自定义的列模板来创建图像列,并使用CSS来控制图像大小。
举个例子:
<el-table :data="tableData">
<el-table-column label="图像">
<template slot-scope="scope">
<img :src="scope.row.imageUrl" style="width: 100px; height:100px;">
</template>
</el-table-column>
<el-table-column prop="name" label="名称">
</el-table-column>
<el-table-column prop="age" label="年龄">
</el-table-column>
</el-table>
在上面的代码中,我们使用了一个自定义的列模板来显示行数据中的图像。我们将图像的URL传递给一个<img>
元素,我们使用CSS来设置图像的大小。
要根据表格列宽自动调整图像大小,可以使用CSS中的max-width
属性。
<el-table :data="tableData">
<el-table-column label="图像">
<template slot-scope="scope">
<img :src="scope.row.imageUrl" style="max-width: 100%; max-height: 100px;">
</template>
</el-table-column>
<el-table-column prop="name" label="名称">
</el-table-column>
<el-table-column prop="age" label="年龄">
</el-table-column>
</el-table>
在这个例子中,我们将图像的max-width
设置为100%
,确保它不会超出列宽。我们也将max-height
设置为100px
,以确保图像高度不会超过100px。