I created a custom Dropzone with vue2Dropzone:
<drop-zone :options="MydropzoneOptions" :include-styling="false" @vdropzone-success="UploadSuccess" @removeUpload="removeFile" id="MyDropzoneID" ref="MyDropzone" :useCustomSlot=true>
<div class="dropzone-custom-content">
<h3>Upload Here</h3>
</div>
</drop-zone>
The uploaded files are then displayed in a seperate div with the id="uploaded":
<div id="uploaded" class="dropzone-previews">
<h3>Uploaded Files:</h3>
<template v-for="(UploadFile,index) in MyUploads">
<img :src="UploadFile.Dateiname"><a title="Delete this file" @click="$emit('removeUpload')">Delete</a>
</template>
</div>
In the 'uploaded' div, beside each uploaded image (thumbnail) there is a link to delete each file. But I don't know how to implement this function. The documentation says there's a method called removeFile(file):
.removeFile(file) -->Removes a file from the dropzone area.
I created a method called removeThisFile, launched @click="removeThisFile":
removeThisFile: function(){
this.$refs.MyDropzone.removeFile()
console.log("File removed!")
}
But the result was the console saying "this.$refs.Mydropzone is undefined, which makes sense now, since only the DOM object can pass the needed file infos. So I decided to try the version you see at the beginning:
<div><a[..] @click="$emit('removeUpload')></a></div>
and in the drop-zone DOM object there's a listener to this, launching my method "removeThisFile".
<drop-zone [..] @removeUpload="removeThisFile" [..]></drop-zone>
But this also isn't working, I don't know why, since I get no error in the console, but also the method isn't launched, since there's also no "File removed!" in the console.
Why isn't it working, is this at all the right way to do this?
You have to pass
removeFile
the file that you want to remove.So you can set your click handler to
@click="removeThisFile(UploadFile)"
and thenremoveThisFile
needs to become: