vant 图片上传 多图上传

2024-04-20 16:08
文章标签 图片 上传 vant 多图

本文主要是介绍vant 图片上传 多图上传,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.mpvue 中使用了vant-weapp中多图上传

先上代码

data中要定义个数组存放图片
定义数据

data(){return {fileList: []}
}

html

<ul style="display:block;clear:both;margin:13px 10px;width:88%"><li v-for="(item,index) in fileList" :key="index" style="width:30%;float:left;position:relative"><image :src="item" style="width:77px;height:77px;background:rgba(247,248,250);border-radius:5px"></image><div class="closeImg" @click="closeImg(index)"><van-icon name="cross" custom-style="color:#fff;font-size:12px" /></div></li><li><image @click="afterRead" style="width:77px;height:77px;text-align:center;line-height:77px;background:rgba(247,248,250);margin-left:7px;border-radius:5px;position:relative"><span class="iconfont uploadimg">&#xe688;</span></image></li>
</ul>

js

// 转base64
base64({url,type}){return new Promise((resolve, reject) => {wx.getFileSystemManager().readFile({filePath: url, //选择图片返回的相对路径encoding: 'base64', //编码格式success: res => {resolve('data:image/' + type.toLocaleLowerCase() + ';base64,' + res.data)},fail: res => reject(res.errMsg)})})
},//上传async afterRead(file){var count = 1;var that = this;wx.chooseImage({count: count,sizeType: ['compressed'],sourceType: ['album'],success(res) {var tempFilePaths = res.tempFilePaths;for (let i = 0; i < res.tempFilePaths.length; i++) {wx.compressImage({// 图片压缩src: res.tempFilePaths[i],quality: 1,success(res) {console.log(res,'===compressImage')wx.getFileSystemManager().readFile({filePath: res.tempFilePath, //选择图片返回的相对路径encoding: "base64",//这个是很重要的success: res => { //成功的回调if (that.fileList.length >= 2) {Toast.fail('最多上传两张');return;}//返回base64格式let base64_img = `data:image/png;base64,${res.data}`;wx.compressImage({// 图片压缩src: base64_img,quality: 30,success(res) {console.log(res)}})console.log(base64_img)Toast.success('图片上传成功');that.fileList.push(base64_img)}})}}}})},//删除图片closeqmImg(index){this.fileListqm.splice(index,1);},// 图片压缩dealImage(res) {var that = this;console.log(res);wx.compressImage({// 图片压缩src: res.path,quality: 1,success(res) {console.log(res)}})}

css样式

.van-popup--center{margin-top: 43px;
}
.iconfont {font-family: "iconfont" !important;font-size: 16px;font-style: normal;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;
}
.cellss{align-items:center;
}
.value-class {flex: none !important;
}
.van-field__label{color: #299cff !important;
}
.van-checkbox{height: 48px !important;
}
.shqm{display: block;margin: 16rpx auto;width: 92%;font-size: 15px;line-height: 31px;color: #299cff;
}
.uploadimg{position: absolute;top: 0;left:0;right: 0;bottom: 0;margin: auto;font-size: 26px;color: #a2a4a5;
}
.h7{height: @h7;background: @bg_eee;
}
.agreement{width: @w90;height: 180px;margin: 12px auto 12px auto;border: 1px dashed #eee;
}
.idcard{display: block;margin: 14px auto;width: 91%;font-size: 17px;text-align: left;color: @color999;
}
.closeImg{position:absolute;width:17px;height:17px;background-color:rgba(0,0,0,.8);top:0;right:0;border-bottom-left-radius:57%;text-align: center;line-height: 17px;
}.logoWrap{width: @w80;margin: 40px auto 50px auto;.loginTxt{font-size: 28px;color: @color4040;font-weight: bold;position: relative;margin: 17px 0 6px 0;z-index: 99;}.loginTxt::after{content: '';display: inline;width: 60px;height: 10px;background-color: #3a53aeba;position: absolute;bottom: 2px;left: -2px;z-index: 88;}.notxt {display: block;color: @color4040;font-size: 15px;font-family: Arial, Helvetica, sans-serif;a{display: inline-block;color: rgb(33, 70, 236);}}}
.iptwrap,.signWrap{width: 88%;margin: @m_auto;
}.btn{width: 88%;margin: 85px auto 40px auto;.forget{display: block;margin-top: 17px;text-align: center;color: @color4040;a{color: #2146ec;display: inline-block;}}
}
.countdownSpan{position: fixed;width: 28px;height: 28px;bottom: 240rpx;left: 10rpx;right: 0;background: #0B255B;color: #fff;display: block;z-index: 999999;border-radius: 50%;font-size: 12px;text-align: center;padding: 11px;line-height: 16px;
}
.downBtn{position: fixed;bottom: 3px;left: 0;right: 0;z-index: 999999;
}

这篇关于vant 图片上传 多图上传的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/920708

相关文章

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

关于MongoDB图片URL存储异常问题以及解决

《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

python实现svg图片转换为png和gif

《python实现svg图片转换为png和gif》这篇文章主要为大家详细介绍了python如何实现将svg图片格式转换为png和gif,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录python实现svg图片转换为png和gifpython实现图片格式之间的相互转换延展:基于Py

使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

Python实现图片分割的多种方法总结

《Python实现图片分割的多种方法总结》图片分割是图像处理中的一个重要任务,它的目标是将图像划分为多个区域或者对象,本文为大家整理了一些常用的分割方法,大家可以根据需求自行选择... 目录1. 基于传统图像处理的分割方法(1) 使用固定阈值分割图片(2) 自适应阈值分割(3) 使用图像边缘检测分割(4)

springboot上传zip包并解压至服务器nginx目录方式

《springboot上传zip包并解压至服务器nginx目录方式》:本文主要介绍springboot上传zip包并解压至服务器nginx目录方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录springboot上传zip包并解压至服务器nginx目录1.首先需要引入zip相关jar包2.然

C#实现将Excel表格转换为图片(JPG/ PNG)

《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

使用Node.js制作图片上传服务的详细教程

《使用Node.js制作图片上传服务的详细教程》在现代Web应用开发中,图片上传是一项常见且重要的功能,借助Node.js强大的生态系统,我们可以轻松搭建高效的图片上传服务,本文将深入探讨如何使用No... 目录准备工作搭建 Express 服务器配置 multer 进行图片上传处理图片上传请求完整代码示例

基于Python实现高效PPT转图片工具

《基于Python实现高效PPT转图片工具》在日常工作中,PPT是我们常用的演示工具,但有时候我们需要将PPT的内容提取为图片格式以便于展示或保存,所以本文将用Python实现PPT转PNG工具,希望... 目录1. 概述2. 功能使用2.1 安装依赖2.2 使用步骤2.3 代码实现2.4 GUI界面3.效