<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> </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>以上代码如何显示图片

时间: 2024-01-21 09:18:02 浏览: 19
你可以在 `el-table-column` 的 `render` 属性中编写一个函数,将图片 URL 渲染为图片元素。例如: ```html <el-table-column prop="img" label="图片url" sortable :render="renderImg" /> function renderImg(scope) { return <img src={scope.row.img} style="max-width:100%;max-height:100%;" />; } ``` 这里使用了 Vue 3 中的 JSX 语法,需要在项目中安装 `@vue/babel-plugin-jsx` 和 `@vue/babel-preset-app`,并在 `.babelrc` 中配置: ```json { "presets": ["@vue/app"], "plugins": [["@vue/babel-plugin-jsx", { "injectH": false }]] } ``` 当然,如果你不想使用 JSX,也可以在 `render` 属性中直接写一个函数式组件。
相关问题

<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>修改以上代码,是他能够显示图片

在模板中,你已经将图片的 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> ``` 这样就可以正确显示图片了。

<el-table :data="tableData" stripe size="medium" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="id" label="ID" width="80" sortable></el-table-column> <el-table-column prop="goodName" label="图书名称"></el-table-column> <el-table-column prop="price" label="图书单价"></el-table-column> <el-table-column prop="num" label="图书数量"></el-table-column> <el-table-column prop="img" label="图片"> <template v-slot="scope"> <el-image :src="scope.row.img" style="width: 100px; height: 100px"></el-image> </template> </el-table-column> 添加注释

这是一个使用了 Element UI 中的 el-table 组件展示数据的代码片段,其中: - data 属性绑定了一个名为 tableData 的数组,用于存储要展示的数据。 - stripe 属性设置为 true,表示表格显示斑马线样式。 - size 属性设置为 medium,表示表格大小为中等。 - @selection-change 事件绑定了一个名为 handleSelectionChange 的方法,用于处理表格中选中行的变化。 - el-table-column 组件用于定义表格的列,其中 type="selection" 表示该列为复选框列,prop 属性指定了该列对应数据对象的属性名,label 属性指定了该列的表头名称,width 属性设置了该列的宽度,sortable 属性设置为 true,表示该列可以排序。 - 在第四列中,添加了一个插槽(slot),用于自定义该列的内容。在该插槽中,使用了 el-image 组件展示了图片。通过 scope.row.img 获取了该行数据对象中 img 属性的值,并将其作为 el-image 组件的 src 属性值。

相关推荐

<el-form-item label="联系人" prop="contactsList"> <el-button type="primary" link :disabled="dialogType === 'check'" @click="handleContactsInfo">添加</el-button> <el-table :data="infoForm.contactsList" border stripe size="small"> <el-table-column label="姓名" prop="ContactsName"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsName" maxlength="20" placeholder="请填写姓名" show-word-limit ></el-input> </template> </el-table-column> <el-table-column label="部门" prop="ContactsDepartment"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsDepartment" maxlength="20" show-word-limit placeholder="请填写部门" ></el-input> </template> </el-table-column> <el-table-column label="职务" prop="ContactsDuty"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsDuty" maxlength="20" show-word-limit placeholder="请填写职务" ></el-input> </template> </el-table-column> <el-table-column label="联系方式" prop="ContactNumber"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactNumber" maxlength="50" show-word-limit placeholder="请填写联系方式" ></el-input> </template> </el-table-column> <el-table-column label="操作" width="56px"> <template #default="{ $index }"> <el-button type="primary" link size="small" :disabled="dialogType === 'check'" @click="handleRemove($index)" > 删除 </el-button> </template> </el-table-column> </el-table> </el-form-item> 该表单初始就有一个,且至少保留一个,对表单内姓名一栏进行必填校验

最新推荐

recommend-type

需要系数法负荷计算软件.zip

需要系数法负荷计算软件
recommend-type

kettle插件-MongoDB Delete2.0

kettle 用于(按条件)删除MongoDB集合数据的插件。 只需要放入kettle 客户端安装目录的 plugins目录下,然后重启kettle客户端即可。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用matlab绘制高斯色噪声情况下的频率估计CRLB,其中w(n)是零均值高斯色噪声,w(n)=0.8*w(n-1)+e(n),e(n)服从零均值方差为se的高斯分布

以下是用matlab绘制高斯色噪声情况下频率估计CRLB的代码: ```matlab % 参数设置 N = 100; % 信号长度 se = 0.5; % 噪声方差 w = zeros(N,1); % 高斯色噪声 w(1) = randn(1)*sqrt(se); for n = 2:N w(n) = 0.8*w(n-1) + randn(1)*sqrt(se); end % 计算频率估计CRLB fs = 1; % 采样频率 df = 0.01; % 频率分辨率 f = 0:df:fs/2; % 频率范围 M = length(f); CRLB = zeros(M,1); for
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这
recommend-type

python中从Excel中取的列没有了0

可能是因为Excel中的列被格式化为数字,而数字前导的0被省略了。可以在Excel中将列的格式更改为文本,这样就会保留数字前导的0。另外,在Python中读取Excel时,可以将列的数据类型指定为字符串,这样就可以保留数字前导的0。例如: ```python import pandas as pd # 读取Excel文件 df = pd.read_excel('data.xlsx', dtype={'列名': str}) # 输出列数据 print(df['列名']) ``` 其中,`dtype={'列名': str}`表示将列名为“列名”的列的数据类型指定为字符串。