uni-app使用uni-file-picker上传组件实现多文件上传功能
-
<uni-file-picker
-
file-mediatype="all"
-
v-model="fileList3"
-
mode="grid"
-
@select="select"
-
@progress="progress"
-
@success="success"
-
@delete ="deletephoto"
-
@fail="fail"
-
ref="upload"
-
limit="5"
-
/>
-
</uni-file-picker>
组件代码
-
// // 选择上传触发函数
-
select(e) {
-
// 根据所选图片的个数,多次调用上传函数
-
let promises=[]
-
for (let i = 0; i < e.tempFilePaths.length; i ) {
-
const promise =this.uploadFiles(e.tempFilePaths,i)
-
promises.push(promise)
-
}
-
Promise.all(promises).then(()=>{
-
-
})
-
},
-
// 上传函数
-
async uploadFiles(tempFilePaths,i){
-
let that =this
-
await uni.uploadFile({
-
url: that.action, //后端用于处理图片并返回图片地址的接口
-
filePath:tempFilePaths[i],
-
name: 'file',
-
header:that.header,
-
success: res => {
-
let data=JSON.parse(res.data) //返回的是字符串,需要转成对象格式
-
if(data.code==200){
-
that.form.attachment.push(data.data)
-
if(i==tempFilePaths.length-1)
-
this.form.attachment=JSON.stringify(this.form.attachment);
-
}
-
},
-
fail: () => {
-
console.log("err");
-
}
-
})
-
-
},
-
// 移出图片函数
-
async deletephoto(){
-
this.form.attachment = ''
-
},
选择以及发生请求代码,可以实现多文件上传功能
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgabcfc
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
photoshop蒙版画笔没反应怎么办
PHP中文网 06-24