takePhoto function var that = this; wxchooseMedia count 3 mediaType image选择的图片尺寸 原图压缩图 sizeType original选择的图片尺寸 原图压缩图 sourceType camera相册选图相机拍照 success functionres
要将图片显示在页面上,需要在wxml文件中添加一个image标签,并绑定图片路径。
首先,在wxml文件中找到要显示图片的位置,添加以下代码:
然后,在.js文件中修改代码如下:
takePhoto: function() { var that = this; wx.chooseMedia({ count: 3, mediaType: ['image'],//选择的图片尺寸 原图,压缩图 sizeType: ['original'],//选择的图片尺寸 原图,压缩图 sourceType: ['camera'],//相册选图,相机拍照 success: function(res) { var tempImagePath = res.tempFilePaths[0]; // 将图片路径添加到images数组中 var images = that.data.images; images.push(tempImagePath); that.setData({ images: images }); } }) }
在success回调函数中,将获取到的图片路径tempImagePath添加到images数组中,并使用setData方法更新data中的images数据。
最后,将images数组绑定到wxml文件中的image标签上,如下所示:
这样就可以将选择的图片显示在页面上了
原文地址: https://www.cveoy.top/t/topic/hNm5 著作权归作者所有。请勿转载和采集!