点击上传图片按钮,并将上传的图片在模拟器中显示
<button bindtap="uploadImg">上传图片</button>
<view>
<image src="{{item}}" wx:for="{{images}}" wx:key="index"></image>
</view>
uploadImg()函数错误写法
//js代码
uploadImg(){
wx.chooseImage({
count: 4,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success (res){ //更改为success:res=>
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths
console.log(tempFilePaths)
this.setData({
images:this.data.images.concat(tempFilePaths)
})
}
})
},
控制台报错如下
正确写法(更改第六行)
uploadImg(){
wx.chooseImage({
count: 4,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success:res=> {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths
console.log(tempFilePaths)
this.setData({
images:this.data.images.concat(tempFilePaths)
})
}
})
},