您现在的位置是:网站首页> 编程资料编程资料
微信小程序实现多文件或者图片上传_javascript技巧_
2023-05-24
434人已围观
简介 微信小程序实现多文件或者图片上传_javascript技巧_
本文实例为大家分享了微信小程序实现多文件或者图片上传的具体代码,供大家参考,具体内容如下
html
上传事件相关资料或文件(jpg/pdf/word) (选填)
js
data: { isHidden: true,//原始添加 url: [],//上传文件路径 type: '',//上传文件类型 uploaderList: [],//上传文件数组 showModal: false, }, // // 上传图片 upImg() { var that = this wx.chooseMessageFile({ count: 1, type: 'all', success(res) { // tempFilePath可以作为img标签的src属性显示图片 // console.log('vvvvvvvv',res.tempFiles) const tempFilePaths = res.tempFiles[0].path const type = res.tempFiles[0].type wx.uploadFile({ url: app.globalData.urlSrc + '/api/chuan/index', filePath: tempFilePaths, name: 'file', success(res) { const datas = JSON.parse(res.data) console.log('上传文件', datas) var status = datas.status that.data.list if (status == 1) { var upFiles = datas.data if (upFiles != '') { let tempFile = tempFilePaths; let uploaderList = that.data.uploaderList.concat(tempFile);//返回页面的图片数据 that.data.url = that.data.url.concat(upFiles);//传给后台的图片数据 that.setData({ type: type, uploaderList: uploaderList }) } } } }) } }) }, // 删除上传 close(e) { var that = this var nowList = [];//新数据 var uploaderList = that.data.uploaderList;//原数据 for (let i = 0; i < uploaderList.length; i++) { if (i == e.currentTarget.dataset.index) { continue; } else { nowList.push(uploaderList[i]) } } that.setData({ uploaderList: nowList, isHidden: true }) },css
.list1 { width: 670rpx; margin: 0 auto; } .tops { display: flex; margin-bottom: 22rpx; } .left1 { margin-left: 12rpx; line-height: 44rpx; text-align: left; } .listImg1 { width: 44rpx; height: 44rpx; margin-left: 24rpx; } .textarea1 { width: 670rpx; height: 250rpx; line-height: 40rpx; border-radius: 44rpx; background-color: rgba(255, 255, 255, 1); color: rgba(16, 16, 16, 1); font-size: 14px; text-align: left; border: 1px solid rgba(240, 240, 240, 1); margin:0 auto; padding: 20rpx 40rpx; box-sizing: border-box; margin-bottom: 40rpx; } .jia{ width: 140rpx; height: 140rpx; margin-top: 40rpx; } .jia image{ width: 140rpx; height: 140rpx; } .cell { width: 100%; overflow: hidden; } .jinListImg { width: 140rpx; height: 140rpx; border-radius: 24rpx; } .close1 { width: 40rpx; height: 40rpx; position: absolute; margin-left: 100rpx; } .jia1 { float: left; position: relative; }示例图

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- Vue-admin-template 报Uncaught (in promise) error问题及解决_vue.js_
- 图解Vue 响应式流程及原理_vue.js_
- Vue.nextTick纯干货使用方法详解_vue.js_
- 微信小程序自定义滚动选择器_javascript技巧_
- 非常全面的12种js数组去重的方法_javascript技巧_
- jquery实现手风琴展开效果_jquery_
- 前端取消请求及取消重复请求方式_JavaScript_
- js前端实现word excel pdf ppt mp4图片文本等文件预览_JavaScript_
- vue中使用echarts实现动态数据绑定以及获取后端接口数据_vue.js_
- 前端vue-cropperjs实现图片裁剪方案_vue.js_
