最近uniapp项目中接收到图片的base64编码,想要实现图片预览。
1、首先要安装插件image-tools,插件地址:https://ext.dcloud.net.cn/plugin?id=123

npm i image-tools --save

2、引入

import {
			pathToBase64,
			base64ToPath
		} from 'image-tools'

3、使用
 

openImg(){//预览图片	
				let that = this;
				uni.showLoading({
					title: "加载中..."
				})
				var arr=[];
				base64ToPath(this.bimg)
					.then(path => {
						console.log('----',path);
						uni.hideLoading()
						arr[0] = path;
						uni.previewImage({
							current: 0,
							urls: arr
						});
					})
					.catch(error => {
						// 图片加载失败
						uni.hideLoading()
					})
					
			},

更多推荐