takePhoto function var that = this; wxchooseMedia count 3 sizeType original mediaType image sourceType camera success functionres
您遇到的问题是因为that.data.images未定义,导致无法进行push操作。您可以在data中定义一个空数组images,然后再进行操作。修改后的代码如下所示:
takePhoto: function() {
var that = this;
wx.chooseMedia({
count: 3,
sizeType: ['original'],
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
});
}
});
},
这样,如果that.data.images未定义,就会使用一个空数组来进行push操作
原文地址: http://www.cveoy.top/t/topic/ievJ 著作权归作者所有。请勿转载和采集!