To display the captured photos, you can modify the code as follows:

  1. Add a new property in the data object to store the image URLs:
data: {
  images: [], // Add this line to store the image URLs
},
  1. Update the success callback function of wx.chooseMedia to push the uploaded image URL to the images array:
success: function(res) {
  const tempFilePaths = res.tempFilePaths;
  console.log("选择成功", res)
  for (let i = 0; i < tempFilePaths.length; i++) {
    wx.cloud.uploadFile({
      cloudPath: 'myImage/' + fullDate + '/' + new Date().getTime() + "_" + Math.floor(Math.random() * 1000) + ".jpg",
      filePath: tempFilePaths[i],
      success: res => {
        console.log("上传成功", res.fileID)
        that.setData({
          images: that.data.images.concat(res.fileID) // Push the uploaded image URL to the images array
        })
        wx.showToast({
          title: '上传成功',
        })
      }
    })
  }
},
  1. In your HTML template, add an image tag with a wx:for loop to display the images:
<image wx:for="{{images}}" wx:key="{{index}}" src="{{item}}"></image>

With these modifications, the captured photos should be displayed on the page

takePhoto function const that = this; const year = new DategetFullYeartoString; const month = new DategetMonth + 1toStringpadStart2 0; const day = new DategetDatetoStringpadStart2 0; c

原文地址: https://www.cveoy.top/t/topic/hLKg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录