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

相关文章

JAVA读取MongoDB中的二进制图片并显示在页面上

1:Jsp页面: <td><img src="${ctx}/mongoImg/show"></td> 2:xml配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001

在服务器上浏览图片

@StarSky 2018-10-26 15:09 字数 15971 阅读 28 https://www.zybuluo.com/StarSky/note/1294871 来源 2018-09-27 线上服务器安装 imgcat Tool   2018-09-27 线上服务器安装 imgcat 0. 准备文件:iterm2_shell_integration.bash1. 在有权限

el-upload 上传图片及回显照片和预览图片,文件流和http线上链接格式操作

<div v-for="(info, index) in zsjzqwhxqList.helicopterTourInfoList" :key="info.id" >编辑上传图片// oss返回线上地址http链接格式:<el-form-itemlabel="巡视结果照片":label-width="formLabelWidth"><el-upload:action="'http:

【QML】用 Image(QQuickPaintedItem) 显示图片

大体功能: 频繁地往界面推送图片,帧率达到视频效果。捕获画布上的鼠标事件和键盘事件。 代码如下: // DrawImageInQQuickPaintedItem.pro 代码如下:QT += quick# You can make your code fail to compile if it uses deprecated APIs.# In order to do so, uncom

用Ps将PSD切片并将切片保存为透明背景的图片

第一步:选择放大镜工具或者Ctrl++将要切片的部分放大。 第二步:选择移动工具单击要切片的部分,在右边的图层栏找到要切片的图层在文字上右键选择转换为智能对象,再右键该图层的文字选择栅格化图层。 第三步:单击选中所要切片的部分,然后Ctrl+A、Ctrl+C、Ctrl+N(背景内容选择透明)、Ctrl+V、Ctrl+S(将文件保存为PNG格式),这样就可以得到透明背景的图片了!

Android性能优化系列之Bitmap图片优化

在Android开发过程中,Bitmap往往会给开发者带来一些困扰,因为对Bitmap操作不慎,就容易造成OOM(Java.lang.OutofMemoryError - 内存溢出),本篇博客,我们将一起探讨Bitmap的性能优化。 为什么Bitmap会导致OOM? 1.每个机型在编译ROM时都设置了一个应用堆内存VM值上限dalvik.vm.heapgrowthlimit,用来限定每个应用可

加载网络图片显示大图

1.将图片的uri列表和下标传给ImagePagerActivity public void imageBrower(int position, ArrayList<String> urls2) {Intent intent = new Intent(this, ImagePagerActivity.class); intent.putExtra(ImagePagerActivity

html标签转换成img图片

app 里的元素需要转换成图片 <script src="../assets/js/html2canvas.min.js"></script>$(function () {html2canvas(document.querySelector("#app"), {useCORS: true}).then(canvas => {layer.close(vm.layerIndex)var img =

Typora撰写Markdown文档上传到github上图片显示问题

OS:Windows 软件:Typora 相信很多人都有撰写Markdown文档的需求,在这里首先安利一下Markdown撰写利器---typora。 Typora支持多种快捷方式生成markdown语法,快速入门,排版整齐漂亮。 当我们向markdown中粘贴图片资源的时候,会自动提示保存图片到...  这时我们可以在存放markdown文档的地方建立一个assert或者pic静态资源文

Jupiter notebook显示数据和图片 备忘

import cv2 as cvimport numpy as np%matplotlib inline #将图片显示在页面内np.set_printoptions(threshold=np.inf) #显示大量数据 path = '/Users/yuanl/Desktop/test1.jpg'img = cv.imread('/Users/yuanl/Desktop/test1.jpg',