首页 > 其他分享 >根据后端id去请求拿取图片组件

根据后端id去请求拿取图片组件

时间:2024-01-18 17:36:21浏览次数:22  
标签:后端 getFileInfoApi newValue result 组件 import data id

1.组件

<template>
  <img
	:src="srcImg ? srcImg : defaultImage ? getDefaultImage : ''"
	v-bind="{ ...otheAttribute }"
	alt=""
  />
</template>

<script>
import { getFileInfoApi } from '@/api/file/index';
export default {
  name: 'imageShow',
  props: {
	fileId: {
	  type: String
	},
	defaultImage: {
	  type: String,
	  default: ''
	}
  },
  data() {
	return {
	  srcImg: '',
	  otheAttribute: {}
	};
  },
  computed: {
	getDefaultImage() {
	  return new URL(`/src/${this.defaultImage}`, import.meta.url);
	}
  },
  watch: {
	fileId: {
	  handler(newValue) {
		if (newValue && newValue != '0') {
		  this.getFileInfoApi(newValue);
		}
	  },
	  immediate: true
	}
  },
  methods: {
	async getFileInfoApi(params) {
	  try {
		const result = await getFileInfoApi({
		  id: params
		});
		if (result?.success) {
		  this.srcImg = result?.data?.url;
		  delete result?.data?.url;
		  this.otheAttribute = result?.data;
		}
	  } catch (err) {
		console.error(err);
	  }
	}
  }
};
</script>

<style lang="less" scoped></style>

2.注册

import ImageShow from '@/components/imageShow/index.vue';
app.component('ImageShow', ImageShow);

3.使用

<ImageShow :fileId="i.snapshot" defaultImage="assets/img/clientHome/data.png" />

标签:后端,getFileInfoApi,newValue,result,组件,import,data,id
From: https://www.cnblogs.com/songkomei/p/17972972

相关文章

  • 一文掌握Vue3函数式组件中的confirm实现技巧!
    在做后台项目时候,使用声明式组件比较多,就是写一个.vue文件,在里面写template、script、style哪里需要,就在哪里导入。而对于前台项目而言,我们期望可以直接通过方法的形式调用,利用函数式组件,在封装时除了要写.vue,还要多一个手动渲染和卸载的步骤。我们可以通过h函数可以生成一个vno......
  • vue+antd-vue(自定义iconfont图标组件)
    1.方式一代码如下import{createFromIconfontCN}from'@ant-design/icons-vue';constIconFont=createFromIconfontCN({scriptUrl:newURL('./assets/font/iconfont.js',import.meta.url).href});app.component('IconFont',IconFont);......
  • BOSHIDA 探索直流电源模块的应用领域
    BOSHIDA探索直流电源模块的应用领域直流电源模块广泛应用于许多领域,包括电子设备、通信、工业自动化、航空航天等。以下是一些常见的应用领域: 1.电子设备:直流电源模块用于给各种电子设备供电,如计算机、手机、平板电脑、摄像机等。2.通信:直流电源模块用于为通信设备供电,如......
  • 解决vue用axiso两次访问后台api,发现后台的sessionID不一致
    我用的是ASP.NETCore7.0做的后台api,在解决了跨域问题(这个问题在官网上就有答案https://learn.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-7.0)为了方便阅读,我再讲一下在里progam里面增加代码(黄色代码),代码格式我就把不变的放到一起了解决完这个之后,因为要......
  • 异步加载树形组件(antd-vue)
    1、html<a-directory-tree:tree-data="useDataSourceTreeList"v-model:selectedKeys="selectedKey"v-if="datasourceId"blockNodeclass="tree-card":showIco......
  • 使用JSZip库解压后台返回的Blob格式文件,并回显到element-ui的el-upload组件
    有一个报告列表,点击编辑的时候需要回显新建时上传的附件。后台提供了一个下载接口,但是会将所有上传的文件打包为一个压缩的blob。类似这种:leturlArr=[];urlArr=urlArr.concat(this.downLoadUrl.split(";"));this.$http.downLoadFile({url:urlArr.......
  • idea 项目编译内存溢出解决配置
    https://blog.csdn.net/malin970824/article/details/89843478 以下几种方式都可尝试下:1.在idea安装的bin目录修改配置文件 -Xms512m-Xmx2024m-Xss4M-XX:MaxPermSize=2024m 2.修改settings 3.修改tomcat-server-Xms512m-Xmx2024m-Xss4M-XX:PermSize=512M-XX:......
  • android navigationBarDividerColor 无效
    AndroidnavigationBarDividerColor无效问题解析与解决1.问题背景在开发Android应用程序时,我们经常会使用导航栏(NavigationBar)来提供用户导航和操作的功能。导航栏中的分割线(divider)是一种常见的设计元素,用于分隔不同的导航按钮或操作按钮。在Android中,我们可以使用navigationB......
  • Android studio 集成github copilot
    AndroidStudio集成GitHubCopilot引言在软件开发的过程中,编写代码是一个不可避免的环节。而对于一些常见的代码块,我们可能已经写了很多次。在这种情况下,GitHubCopilot可以成为我们的好帮手。GitHubCopilot是由GitHub开发的人工智能代码助手,它通过学习开源代码库中的代码......
  • Android navigationBarDividerColor
    实现AndroidnavigationBarDividerColor的步骤流程图flowchartTDA(开始)B(查找navigationBar对象)C(创建dividerDrawable对象)D(设置dividerDrawable为navigationBar的dividerDrawable属性)E(结束)A-->B-->C-->D-->E介绍在Android开发......