Implementation code of WeChat applet picture preview function

小云云
Release: 2018-05-11 17:09:25
Original
3074 people have browsed it

Image preview is a very common function. This article mainly introduces the image preview function of WeChat applet in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

Rendering

Implementation code of WeChat applet picture preview function

Principle

  • Use wx.chooseImage to select a local image;

  • Use wx.previewImage to preview images.

##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>
Copy after login

WXSS

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

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
  })
 }
})
Copy after login

Note

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

Related recommendations:


AJAX method to implement image preview and upload and generate thumbnails

nodejs to implement image preview and Upload sample code

JQuery uses uploadView to implement the image preview upload function

The above is the detailed content of Implementation code of WeChat applet picture preview function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!