fail parameter error: parameter.src should be String instead of Array

在开发小程序,保存图片功能时,

// 保存图片
getImageInfo() {
var _this = this
wx.showLoading({
title: ‘图片生成中…’,
})
wx.getImageInfo({
src: this.data.imageSrc,
success: function (res) {

提示“fail parameter error: parameter.src should be String instead of Array;”,意思是要String类型,但data.imageSrc是数组列类型,然后查找源头,果然发现获取的图片是数组类型

chooseimage: function () {
var _this = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: [‘original’, ‘compressed’], // 可以指定是原图还是压缩图,默认二者都有
sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
_this.setData({
imageSrc: res.tempFilePaths
})
}
})
},
改成imageSrc: res.tempFilePaths[0]就正常了。

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注