// pages/add/add.js const db = wx.cloud.database() Page({ /** * 页面的初始数据 */ data: { tempImgList:[], cloudDetailImage:[] }, onLoad: function (options) { }, onShow: function () { this.getTypeGoodsList() }, getTypeGoodsList(){ db.collection('good_Type').get() .then(res=>{ console.log("查找分类目录成功",res) let List = res.data let typeList=[] for(let i =1;i<List.length;i++){ typeList.push(List[i]) } this.setData({ typeList:typeList }) }) .catch(res=>{ console.log("查找分类目录失败",res) }) }, getType(event){ console.log(event) this.setData({ currentIndex:event.currentTarget.dataset.index, type_nameCN:this.data.typeList[event.currentTarget.dataset.index].type_nameCN }) }, chooseDetailImage(){ var that = this; wx.chooseMedia({ count: 9, mediaType: ['image','video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', success(res) { console.log(res.tempFiles.tempFilePath) console.log(res.tempFiles.size) //上传图片 that.uploadImageDetail() } }) }, uploadImageDetail(){ var that = this; for(let l in this.data.tempImgList){ wx.cloud.uploadFile({ cloudPath: 'goodImage/${Math.random()}_${Date.now()}.${this.data.tempImgList[l].match(/\.(\w+)$/)[l]}', filePath: this.data.tempImgList[l], success(res){ console.log(res.fileID) that.data.cloudDetailImage.push(res.fileID) that.setData({ cloudDetailImage:that.data.cloudDetailImage }) } }) } } }) 上传图片没反应
时间: 2023-06-26 10:05:21 浏览: 99
node.docx Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时环境,可以用于开发服务
可能是因为上传图片的函数`uploadImageDetail()`没有被调用。你可以在`chooseDetailImage()`中调用`uploadImageDetail()`函数,例如这样:
```
chooseDetailImage(){
var that = this;
wx.chooseMedia({
count: 9,
mediaType: ['image','video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
console.log(res.tempFiles.tempFilePath)
console.log(res.tempFiles.size)
that.setData({
tempImgList:res.tempFilePaths
})
//上传图片
that.uploadImageDetail()
}
})
},
```
在`chooseDetailImage()`函数中,首先将选择的图片路径存储到`tempImgList`中,然后再调用`uploadImageDetail()`函数进行图片上传。
阅读全文