<template> <el-table :data="tableData" style="width: 100%" stripe ref="multipleTable" @selection-change="handleSelectionChange" :header-cell-style="{background:'#eef1f6',color:'#606266'}"> <el-table-column prop="id" label="编号" sortable /> <el-table-column prop="img" label="图片url" sortable /> <el-table-column prop="img" label="缩略图"> <template v-slot="products"> <img :src="products.row.img" min-width="70" height="70"/> </template> </el-table-column> <el-table-column prop="image" label="图片" min-width="20%" > <!-- 图片的显示 --> <template #default="scope"> <!--<img :src="scope.row.img" min-width="70" height="70" />--> </template> </el-table-column> <el-table-column align="center" label="图片url"> <template v-slot="products"> <!--<img :src="require('../file/img/' + item)" v-for="item in list" :key="item" alt="">--> <el-image style="width: 100px; height: 100px" :src="products.row.img" ></el-image> <!--<img :src="require(''+products.row.img)" style=" width:100px; height:100px" />--> </template> </el-table-column> </el-table> </template> <script setup> import {ref,toRefs,reactive,onMounted,getCurrentInstance} from 'vue' let { proxy } = getCurrentInstance(); import router from '@/router' onMounted(()=>{ getTableData(); }); //获取表单信息 let tableData = ref([]); function getTableData() { proxy.$http.get('/ImgController/imgFind') .then(res => { tableData.value=res.data; console.log(res.data) }) .catch(err => { console.log(err) }); } </script> <style scoped> </style>修改以上代码,是他能够显示图片
时间: 2023-12-28 13:03:33 浏览: 34
在模板中,你已经将图片的 url 显示在表格中了,但是在显示图片时,需要注意以下几点:
1. 确定图片的 url 是否正确,可以通过控制台检查图片 url 是否可以访问。
2. 确认图片的路径是否正确,这里使用了相对路径,需要确认相对路径是否正确。
3. 确认图片是否过大,可以在 img 标签中设置 width 和 height 属性,或者使用 el-image 组件,控制图片大小。
在代码中,有三个地方需要修改:
1. 第一个 el-table-column 中,图片已经正确显示,不需要修改。
2. 第二个 el-table-column 中,需要将注释的 img 标签打开,同时添加 width 和 height 属性,用于控制图片大小。
```html
<el-table-column prop="image" label="图片" min-width="20%">
<!-- 图片的显示 -->
<template #default="scope">
<img :src="scope.row.img" width="70" height="70" />
</template>
</el-table-column>
```
3. 第三个 el-table-column 中,需要使用 el-image 组件,同时设置宽度和高度。
```html
<el-table-column align="center" label="图片url">
<template v-slot="products">
<el-image style="width: 100px; height: 100px" :src="products.row.img"></el-image>
</template>
</el-table-column>
```
这样就可以正确显示图片了。