vue3 渲染一个后端返回的图片字段渲染、table表格内放置图片

一、后端直接返回图片url

当图片字段接口直接返回的是图片url,可以直接放到img标签上

<img v-if="thumbLoader" class="r-image-loader-thumb" :src="resUrl" />

二、当图片字段接口直接返回的是图片Id

那么就需要去拼一下图片链接

调用下接口吧返回的id传过去拼接即可

复制代码
<img v-if="thumbLoader" class="r-image-loader-thumb" :src="imgSrc" />

 

const imgSrc = computed(() => {
    
        return `/bnc_rest/market/file/${resUrl};
     
});

三、接口直接返回的是图片文件

需要自行拼接

复制代码
------------------------结构部分
<img v-if="thumbLoader" class="r-image-loader-thumb" :src="logo" />

------------------------js部分
import { getEnterpriseLogo } from "@/api/index.js";

const logo = computed(() => {
    let url = "";
    if (props.detail && props.detail.enterpriseVO && 
    props.detail.enterpriseVO.enterpriseId) {
   //在api.js文件里写个方法调用 或者直接拼
      //1.调用的方法
      url = getEnterpriseLogo(props.detail.enterpriseVO.enterpriseId);
      //2.直接在当前页面拼接
      // url = `/bnc_rest/org/orgunits/${props.detail.enterpriseVO.enterpriseId}/logo`;
    }
    return url;
});

api/index.js文件

复制代码
/**
 * 获取企业logo
 */
export const getEnterpriseLogo = id => {
    return `/bnc_rest/org/orgunits/${id}/logo`;
};

四、在table表格里去放置图片字段

用的ui组件库为arco-deiagn vue 组件库

复制代码
 <a-table
                column-resizable
                :bordered="{ headerCell: true, wrapper: false }"
                :data="rtableTableData"
                :scrollbar="false"
                :pagination="false"
                :row-selection="rowSelection"
                @row-click="rowClick"
                v-model:selected-keys="selectedKeys"
                :row-key="rowKey"
                v-bind="{ ...OtherProps }"
                :scroll="scrollConfig"
                @select="rowSelect"
                @select-all="rowAllSelect"
                :span-method="spanMethod"
                ref="tableRef"
            >
                <template #summary-cell="{ column, record }">
                    <div>{{ record[column.dataIndex] }}</div>
                </template>
                <template #columns>
                    <a-table-column align="left" title="序号" v-if="showSeq" :width="showSeqWidth" class="first">
                        <template #cell="{ rowIndex }">{{ currentPageStart + rowIndex }}</template>
                    </a-table-column>
                    <a-table-column
                        v-for="(c, i) in columns"
                        :width="c.width ? c.width : i + 1 < columns.length ? 120 : undefined"
                        :align="c.align ? c.align : 'left'"
                        :title="c.title"
                        :data-index="c.dataIndex"
                        :fixed="c.fixed ? c.fixed : ''"
                        :key="i"
                    >
                        
                        <template #cell="{ rowIndex, record, column }">
                            <!-- 自定义单元格内容 -->
                            <slot
                                :name="c.slotName ? c.slotName : c.dataIndex"
                                :rowIndex="rowIndex"
                                :record="record"
                                :cell="record[column.dataIndex]"
                            >
                                <!-- 图片 -->
                                <template v-if="c.type && c.type == 'img'">
                                    <RImage
                                        v-if="record[column.dataIndex]"
                                        fit="cover"
                                        height="32"
                                        width="100%"
                                        :src="record[column.dataIndex]"
                                        show-loader
                                        class="r-table-content-img"
                                    ></RImage>
                                    <span v-else>-</span>
                                </template>
                                <!-- 附件 -->
                                <template v-else-if="c.type && c.type == 'file'">
                                    <RLink v-model="record[column.dataIndex]" v-if="record[column.dataIndex]"></RLink>
                                    <span v-else>-</span>
                                </template>
                                <div v-else>{{ formatterCell(record, c) }}</div>
                            </slot>
                        </template>
                    </a-table-column>
  </a-table>

此处为表格内单元格的图片放置,对其设置一个表格插槽即可

相关推荐
Cosmoshhhyyy2 小时前
《Effective Java》解读第5条:优先考虑依赖注入来引用资源
java
初遇你时动了情2 小时前
css中backdrop-filter 详细使用 ios毛玻璃效果、filter和backdrop-filter使用说明
前端·css
.柒宇.3 小时前
力扣hot100----15.三数之和(java版)
java·数据结构·算法·leetcode
景彡先生3 小时前
Python Selenium详解:从入门到实战,Web自动化的“瑞士军刀”
前端·python·selenium
程序员卷卷狗3 小时前
JVM 调优实战:从线上问题复盘到精细化内存治理
java·开发语言·jvm
cj6341181504 小时前
【MySQL】mysqldump使用方法
java·后端
JIngJaneIL4 小时前
停车场管理|停车预约管理|基于Springboot的停车场管理系统设计与实现(源码+数据库+文档)
java·数据库·spring boot·后端·论文·毕设·停车场管理系统
杰克尼4 小时前
二分查找为什么总是写错
java·数据结构·算法
Liudef065 小时前
DeepseekV3.2 实现构建简易版Wiki系统:从零开始的HTML实现
前端·javascript·人工智能·html
景早6 小时前
vue 记事本案例详解
前端·javascript·vue.js