原因: uni.previewImage 执行完会触发onShow(这个钩子函数)
// html
<view class="cu-bar bg-white">
<view class="action">
图片描述
</view>
<view class="action">
<!-- {{imgList.length}}/4 -->
</view>
</view>
<view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub">
<view class="bg-img" v-for="(item,index) in imgList" :key="index" @click="showImg(index)"
:data-url="imgList[index]">
<image :src="imgList[index]" mode="aspectFill"></image>
</view>
</view>
</view>
data(){
return {
noexebshowFalg: true
}
}
onShow(){
if(this.noexebshowFalg){
// this.noexebshowFalg为true的时候才会执行 获取数据
}
}
// 点击预览图片
showImg(index) {
this.noexebshowFalg = false; //不允许再次触发onshow这个声明周期
uni.previewImage({
current: index, // 当前显示图片索引值
urls: imgList, // 需要预览的图片链接列表 必须是数组
loop: true // 是否可循环预览
});
},