代码:
<view class="poster" @click="previewImage">
<image :src="$common.image(newDetail.image)" :data-src="newDetail.image" mode="aspectFill">image>
view>
// 预览图片
previewImage(e) {
// 传入的必须是个数组,如果一张图也需要先处理成数组
let imgsArray = [];
imgsArray[0] = e.target.dataset.src;
uni.previewImage({
current: 0,
urls: imgsArray,
success: res => {
console.log("成功");
},
fail: res => {
console.log("失败");
}
});
}

列表里面的列表数据
即为数组中的数组 外层循环之后 内层也有循环
代码:
<view class="item" v-for="(item,index) in postsList" :key="index">
<view v-for="(itemImg,indexImg) in item.images" :key="indexImg" @click="previewImage(index,indexImg)">
<image :src="$common.image(itemImg)" mode="aspectFill">image>
view>
view>
data() {
return {
postsList: [],
}
},
methods:{
// 图片预览
previewImage(index,indexImg) {
console.log(index);
//新增一个图片空数组,把内部的图片数组拿出来赋进去,,当前内含全部图片数组
let photoList =this.postsList.map(item => {
return item.images;
});
console.log(photoList[index]);//我们需要的是当前某条信息的里面的数组
uni.previewImage({
current: indexImg, //默认显示当前点击的图片
urls: photoList[index]
});
}
}
console.log(photoList);

console.log(photoList[index]);



https://uniapp.dcloud.net.cn/api/media/image.html#unipreviewimageobject