飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
const app = getApp()

初始数据: data: { uploadPicList:[] }, 点击上传事件: uploads:
function () { var that = this; wx.chooseImage({ success: function (res) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'https://www.xxx.com/upload.php', filePath: tempFilePaths[0], name: 'file', formData:{ 'user':'cyxxzjp' }, success: function(res){ var dataformat = {imgurl:res.data, title:'上传的图片'} var thispiclist = that.data.uploadPicList thispiclist.push(dataformat) that.setData({ uploadPicList: thispiclist }) } }) }, }) },


 删除功能,只有本地,需要增加request到服务器端删除功能

delpic: function(event){
    var delimg = event.target.dataset.imgurl
    var tp = this.data.uploadPicList
    for(var i=0; i<tp.length; i++){
      if (tp[i].imgurl == delimg){
        tp.splice(i,1)
      }
    }
    this.setData({
      uploadPicList:tp
    })
  }
wxml:
<
button bindtap='uploads'>上传文件/图片</button> <view class='uploadpics' wx:if="{{uploadPicList}}"> <view wx:for="{{uploadPicList}}"> <image src='{{item.imgurl}}' mode='aspectFit'></image> <text>{{item.title}}</text> <view bindtap='delpic' data-imgurl="{{item.imgurl}}">删除</view> </view> </view>

 

posted on 2018-02-08 14:25  飞狐爷  阅读(343)  评论(0编辑  收藏  举报