"takePhoto: function() {\n var that = this;\n wx.chooseMedia()({\n count: 3,\n mediaType: ['image'],//选择的图片尺寸 原图,压缩图\n sizeType: ['original'],//选择的图片尺寸 原图,压缩图\n sourceType: ['camera'],//相册选图,相机拍照\n success: function(res) {\n var tempImagePath = res.tempFilePaths[0];\n // 将图片路径添加到images数组中\n var images = that.data.images;\n images.push(tempImagePath);\n that.setData({\n images: images\n });\n }\n })\n} \n"要将图片显示在页面上,需要在wxml文件中添加一个image标签,并绑定图片路径。\n\n首先,在wxml文件中找到要显示图片的位置,添加以下代码:\n\n\n\n然后,在.js文件中修改代码如下:\n\ntakePhoto: function() {\n var that = this;\n wx.chooseMedia({\n count: 3,\n mediaType: ['image'],//选择的图片尺寸 原图,压缩图\n sizeType: ['original'],//选择的图片尺寸 原图,压缩图\n sourceType: ['camera'],//相册选图,相机拍照\n success: function(res) {\n var tempImagePath = res.tempFilePaths[0];\n // 将图片路径添加到images数组中\n var images = that.data.images;\n images.push(tempImagePath);\n that.setData({\n images: images\n });\n }\n })\n}\n\n在success回调函数中,将获取到的图片路径tempImagePath添加到images数组中,并使用setData方法更新data中的images数据。\n\n最后,将images数组绑定到wxml文件中的image标签上,如下所示:\n\n\n \n\n\n这样就可以将选择的图片显示在页面上了。\n


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

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