uni-app小程序-将后台返回的base64码转为图片时,图片没有显示出来

1.问题:

在用uni-app开发小程序时,遇到一个问题:后台返回一长串码,前端这边需要将base64码进行转化为图片

2.解决方式:

2.1.获取后台返回的base64码

	// 获取base64码转换为图片
	getImgFun() {
    
    
		var that = this;
		this.$api.appPlateForm('POST', this.$url.getImg, '', function(res) {
    
    
			that.imgurl = "data:image/png;base64,"+res.data
		})
	},

2.2.在页面需要的地方进行赋值:
tips:在data中定义imgurl 变量,记得把.replace(/[\r\n]/g,'')这句代码添加上,因为后台返回的会有换行空格之类的,会导致图片显示不出来。

<image :src="imgurl.replace(/[\r\n]/g,'')" style="width: 100%;height: 100%;"></image>

在这里插入图片描述

ending~

猜你喜欢

转载自blog.csdn.net/weixin_48596030/article/details/130970995
今日推荐