有更新,看我主页里最新的那个多张图片上传的
网上找代码找了大半天了,要么是格式缺胳膊少腿到处报错,要么就是单纯的bug,图片渲染层网络层报错,没有let that=this或者res=>{}异步问题,还有js函数之间传值问题,终于弄出来了。
下面是代码
Js
let title = ''
let content = ''
let loadding = 'lodding'
let db = wx.cloud.database()
let datas
Page({
data: {
time: '',
imgPreview: '',
imgList: [],
temFile: ''
},
title_input(e) {
title = e.detail.value
console.log(title)
},
content_input(e) {
content = e.detail.value
console.log(content)
},
chooseImage() {
wx.chooseImage({
count: 9,
sizeType: ['compressed', 'original'],
sourceType: ['album', 'camera'],
success: res => {
// this.uploadImg(res.tempFilePaths[0])
this.setData({
imgList: this.data.imgList.concat(res.tempFilePaths),
temFile: res.tempFilePaths
})
},
fail(err) {
console.log("选择失败", err)
}
})
// 将图片上传至云存储空间
},
uploadImg(temFile) {
for (let i = 0; i < this.data.imgList.length; i++) {
let m = Math.random() * 100
wx.cloud.uploadFile({
cloudPath: ('imgList/帖子/' + m + '.png'), // 指定要上传的文件的小程序临时文件路径
filePath: this.data.temFile[i],
success: res => { // 成功回调
console.log('上传成功', re