Vue2-Dropzone为每个上传的文件添加点击事件

问题描述 投票:0回答:1
vuejs2 vue2-dropzone
1个回答
0
投票

vue2-dropzone 不提供点击事件,但您可以创建自己的点击事件。当

vdropzone-file-added
事件触发时(每当将文件添加到拖放区时都会发生这种情况),您可以使用它来添加单击事件侦听器

<vue-dropzone 
  ref="myVueDropzone"
  :options="dropzoneOptions"
  @vdropzone-file-added="added">
</vue-dropzone>
added(file) {
  if (file.previewElement) {
    // get details overlay element that appears when hovering a thumbnail
    const detailsElement = file.previewElement.querySelector('.dz-details');
    // add click listener to it
    detailsElement.addEventListener('click', () => {
      this.fileClick(file);
    });
  }
},
fileClick(file) {
  const url = URL.createObjectURL(file);
  window.open(url);
}
© www.soinside.com 2019 - 2024. All rights reserved.