点击图片预览Cannot read property '0' of undef..?
找不到是啥原因了,还请各位赐教
WXML内代码如下:windex是获取点击的消息的下标,index是获取点击消息下对应图片的下标
<view class="weibo-group" wx:for="{{weibos}}" wx:for-item="weibo" wx:for-index="windex">
<!-- 一张图片的情况 -->
<view wx:if="{{weibo.weibo.images.length===1}}" class="image-list-group">
<image src="{{weibo.weibo.images}}" wx:for-item="image" src="{{image}}" bindtap="onImageTap"
data-index="0" data-weibo="{{windex}}"> </image>
</view>
<!-- 两张或四张图片情况 -->
<view wx:elif="{{weibo.weibo.images.length===2||weibo.images.length===4}}" class="image-list-group">
<image wx:for="{{weibo.weibo.images}}" wx:for-item="image" src="{{image}}"
bindtap="onImageTap" data-index="{{index}}" data-weibo="{{windex}}">
</image>
</view>
JS内的代码如下:
onImageTap:function(event){
console.log(event)
const dataset = event.target.dataset;
const weiboIndex = dataset.weibo;
const imageIndex = dataset.index;
const images = this.data.weibos[weiboIndex].images;
const current =images[imageIndex];
wx.previewImage({
urls: images,
current:current
})
},
打印event也能有内容,但是在点击图片进行预览的时候就出问题了
event打印内容如下:
报错信息如下: