微信小程序大图预览功能

125 阅读1分钟

wx.previewImage(Object object)

wx.previewImage({
  current: '', // 当前显示图片的http链接
  urls: [] // 需要预览的图片http链接列表
})

注意urls需要的类型

urls需要的类型是字符串数组  Array.<string>

举例:点击轮播图中的图片可以实现大图预览功能

 <view>
     <!--  轮播图 -->
    <swiper indicator-dots circular>
      <swiper-item
        v-for="(item, index) in objectArrty"
        :key="item.id"
      >
        <image
          @click="preview(index)"
          :src="item.urlImg"
          mode="scaleToFill"
        />
      </swiper-item>
    </swiper>
 </view>
 const objectArray=[
     {
       id43982
       urlImg"http://image2.suning.cn"
     },
     {
       id43983
       urlImg"http://image3.suning.cn"
     },
     {
       id43984
       urlImg"http://image4.suning.cn"
     }
 ]
 
 method:{
   preview(current){
      //将对象数组中的图片地址映射出来,变成一个字符串数组
     const urls=this.objectArray.map(item=>item.urlImg)
     wx.previewImage({
      current: '', // 当前显示图片的http链接
      urls // 需要预览的图片http链接列表
     })
  }
}