vant-weapp的uploader组件删图片,多次增加图片

288 阅读1分钟

参考1:juejin.cn/post/684490…

参考2:  juejin.cn/post/684490…

官网链接  vant-contrib.gitee.io/vant-weapp/…

<van-uploader  accept="{{ media }}"  file-list="{{ fileList }}"  deletable="{{ true }}"  max-count="4"  bind:after-read="afterRead"  bind:before-read="beforeRead"  bind:delete="deleteClick"  multiple="{{ true }}"  show-upload="{{ true }}"  preview-image="{{ true }}"  preview-full-image="{{ true }}"/>

data: {    
    fileList: [],
  },



  afterRead(e){    const { fileList } = this.data    console.log('fileList--1',fileList);    wx.showLoading({      title: '上传中...'    });   
    if (fileList.length == 0) {      console.log('第一次上传图片');      this.setData({        fileList :e.detail.file      })    }else{      console.log('再次上传图片');
      console.log('e.detail.file',e.detail.file);
      fileList.concat(e.detail.file) //这个不起作用      console.log('fileList--2',fileList);

      this.setData({        fileList :[...fileList,...e.detail.file] // 这个起作用      })     }         wx.hideLoading()  },
  deleteClick(e){    const delIndex = e.detail.index    const { fileList } = this.data    fileList.splice(delIndex, 1)    this.setData({      fileList    })  },

我是新手,不足之处多包含。