微信小程序> 微信小程序手机照片上传和删除

微信小程序手机照片上传和删除

浏览量:680 时间: 来源:ZhangXD_BLOG

wxml:

  view class="gallery"    !--显示图片--    view class="item" wx:for="{{images}}" wx:key="index"      image src="{{item}}" data-src="{{item}}" bindtap="previewImage" mode="aspectFit" /      !-- 删除按钮 --      view class="delete" bindtap="delete" data-index="{{index}}"        image src='../image/delete.png' mode="widthFix"/image      /view    /view    !--添加图片--    view class="item2" bindtap="chooseImage"      view class='addIcon'+/view    /view  /view

wxss:

.gallery {  background: #fff;  display: flex;  justify-content: flex-start;  flex-wrap: wrap;  padding-bottom: 80px;}/*每张图片所占容器*/.item {  position: relative;  margin: 10rpx 2%;  width: 46%;  height: 442rpx;  background: #f3f3f3;}.item image {  width: 100%;  height: 100%;}/*add按钮*/.item2 {  margin: 10rpx 2%;  width: 45%;  height: 442rpx;  text-align: center;  line-height: 442rpx;  font-size: 200rpx;  background: #fff;  color: #e4e5ea;  border: 1px dashed #e4e5ea;}/*删除按钮*/.delete {  width: 100%;  position: absolute;  left: 0;  bottom: 0;  height: 80rpx;  font-size: 22rpx;  text-align: center;  background-color: rgba(0, 0, 0, 0.3);  display: none;}.delete image {  width: 44rpx;  margin-top: 22rpx;}

重点来了,js:

Page({  data: {    images: [],    pathsTmp: []  },  // 本地选择照片上传  chooseImage: function() {    var that = this    wx.chooseImage({      count: 9,      sizeType: ['compressed'],      sourceType: ['album', 'camera'],      success: function(res) {        that.setData({          //上传完并显示照片          images: that.data.images.concat(res.tempFilePaths)        });      }    })  },  // 删除照片  delete: function(e) {    var that = this;    var index = e.currentTarget.dataset.index;    var images = that.data.images;    images.splice(index, 1);    that.setData({      images: images    });  },})

 

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎