vue element table显示图片
时间: 2023-10-08 21:07:22 浏览: 182
可以使用 Element UI 的 Table 组件中的 `slot-scope` 属性和 `template` 标签来显示图片。
具体步骤如下:
1. 在 Table 组件中设置需要显示图片的列的 `prop` 属性,例如 `image`。
2. 在 Table 组件中使用 `slot-scope` 属性来获取当前行的数据。
3. 在 `template` 标签中使用 `v-bind` 指令来绑定图片的 `src` 属性,例如 `v-bind:src="scope.row.image"`。
以下是一个简单的示例代码:
```html
<template>
<el-table :data="tableData">
<el-table-column prop="name" label="Name"></el-table-column>
<el-table-column prop="image" label="Image">
<template slot-scope="scope">
<img v-bind:src="scope.row.image" style="max-width: 100px;">
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: 'Item 1', image: 'https://via.placeholder.com/150' },
{ name: 'Item 2', image: 'https://via.placeholder.com/150' },
{ name: 'Item 3', image: 'https://via.placeholder.com/150' },
]
}
}
}
</script>
```
在上述代码中,`tableData` 数组中包含了每一行的数据,其中 `image` 属性包含了需要显示的图片的 URL。在 `template` 标签中,使用 `v-bind` 指令来绑定 `img` 标签的 `src` 属性,使其显示当前行的图片。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)