微信小程序如何显示拍摄的图片?
To display the captured photos, you can modify the code as follows:\n\n1. Add a new property in the data object to store the image URLs:\njavascript\ndata: {\n images: [], // Add this line to store the image URLs\n},\n\n\n2. Update the success callback function of wx.chooseMedia to push the uploaded image URL to the images array:\njavascript\nsuccess: function(res) {\n const tempFilePaths = res.tempFilePaths;\n console.log("选择成功", res)\n for (let i = 0; i < tempFilePaths.length; i++) {\n wx.cloud.uploadFile({\n cloudPath: 'myImage/' + fullDate + '/' + new Date().getTime() + "_" + Math.floor(Math.random() * 1000) + ".jpg",\n filePath: tempFilePaths[i],\n success: res => {\n console.log("上传成功", res.fileID)\n that.setData({\n images: that.data.images.concat(res.fileID) // Push the uploaded image URL to the images array\n })\n wx.showToast({\n title: '上传成功',\n })\n }\n })\n }\n},\n\n\n3. In your HTML template, add an image tag with a wx:for loop to display the images:\nhtml\n<image wx:for="{{images}}" wx:key="{{index}}" src="{{item}}"></image>\n\n\nWith these modifications, the captured photos should be displayed on the page.
原文地址: https://www.cveoy.top/t/topic/puRw 著作权归作者所有。请勿转载和采集!