Home  >  Article  >  Web Front-end  >  How to implement image preview function in WeChat mini program

How to implement image preview function in WeChat mini program

亚连
亚连Original
2018-06-08 15:51:472862browse

This article mainly introduces the image preview function of the WeChat applet in detail. It has certain reference value. Interested friends can refer to it.

This article shares the implementation of the WeChat applet for everyone. The specific code for image preview is for your reference. The specific content is as follows

Rendering

How to implement image preview function in WeChat mini program

Principle

  • Usage wx.chooseImage selects a local image;

  • Use wx.previewImage to preview the image.

WXML

<view>
 <button bindtap="previewImage" type="primary">图片上传预览</button>
 <view class="tui-content"> 
  <image class="tui-preview-img" wx:for="{{previewImageArr}}" bindtap="changePreview" src="{{item}}" src="{{item}}"></image>
 </view>
</view>

WXSS

page{background-color: #efeff4;}
.tui-preview-img{
 width: 200rpx;
 height: 120rpx;
}

JS

Page({
 data: {
  previewImageArr:[]
 },
 previewImage(e){
  var self = this;
  wx.chooseImage({
   count:8,
   success(res) {
    var tempFilePaths = res.tempFilePaths;
    self.setData({ previewImageArr: tempFilePaths});
   }
  })
 },
 changePreview(e){
  var self = this;
  wx.previewImage({
   current: e.currentTarget.dataset.src,
   urls: self.data.previewImageArr
  })
 }
})

Note

wx The parameters current and urls of .previewImage must be http links.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Detailed explanation of how to use components and their functions in Vue.js?

Migrate AngularJS1.x application to React (detailed tutorial)

How to implement the shopping cart ball parabola in vue 2.0

The above is the detailed content of How to implement image preview function in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn