takePhoto function var that = this; wxchooseImage wxchooseMedia count 1 sizeTypeoriginal mediaType image sourceType camera success functionres var tempImag
To implement taking three photos and displaying them on the page using wx.chooseMedia instead of wx.chooseImage, you can modify the code as follows:
takePhoto: function() {
var that = this;
wx.chooseMedia({
count: 3,
mediaType: ['image'],
sourceType: ['camera'],
success: function(res) {
var tempFilePaths = res.tempFiles.map(function(file) {
return file.tempFilePath;
});
// Add the image paths to the images array
var images = that.data.images;
images.push(...tempFilePaths);
that.setData({
images: images
});
}
});
},
<view class="photo-list">
<block wx:for="{{images}}" wx:key="index">
<image class="photo" src="{{item}}" mode="aspectFill"></image>
<button class="delete-btn" data-index="{{index}}" bindtap="deleteImage" type="primary" size="mini">删除</button>
</block>
</view>
In this modified code, wx.chooseMedia is used with mediaType: ['image'] to select media of type 'image' and count: 3 to choose three images. The selected image paths are then added to the images array and the images array is updated in the setData function to re-render the images on the page
原文地址: http://www.cveoy.top/t/topic/hNwB 著作权归作者所有。请勿转载和采集!