vue-dropzone
vue-dropzone copied to clipboard
setOption not working
Im trying to set the url dynamically on a dropzone element
Im doing var url ='http://myurl' this.$refs.dropzone1.setOption('url', url)
the error Im getting is...
Uncaught TypeError: Cannot read property 'options' of undefined at VueComponent.setOption (vue2Dropzone.js?2af3:1)
It appears I can't access the options f the dropzone object no matter what I try.
Cab you use chrome dev tools to set a break point to check the reference? I think it should be
this.$refs.dropzone1.dropzone.setOption('url', url)
When I do ...
this.$refs.dropzone1.dropzone.setOption('url', url)
I get ...
Uncaught TypeError: Cannot read property 'setOption' of undefined
If I do ...
this.$refs.dropzone1.setOption('url', url)
I get ...
Uncaught TypeError: Cannot read property 'options' of undefined
So it looks like dropzone1 is set and has setOption as a method. Its just that setOption can't set 'options' because its undefined for some reason??
Hmmm thats weird @holoverse - as you can see here the setOptions method is very straight forward, the only thing I can think is check that your component is mounted properly before you call that method...
Can you tell us any more about your workflow?
For some reason, setOption method doesn't work, as a workaround, I used this brute force approach:
mounted () {
setTimeout(() => {
this.$refs.myVueDropzone.dropzone.options.url = this.uploadUrl
this.$refs.myVueDropzone.dropzone.options.headers = {Authorization: `bearer ${this.token}`}
}, 0);
}
uploadUrl and token are computed properties
For some reason,
setOptionmethod doesn't work, as a workaround, I used this brute force approach:mounted () { setTimeout(() => { this.$refs.myVueDropzone.dropzone.options.url = this.uploadUrl this.$refs.myVueDropzone.dropzone.options.headers = {Authorization: `bearer ${this.token}`} }, 0); }
uploadUrlandtokenare computed properties
you saved my day!
@mabdalmoniem your smile made my day <3
Is there an update to this or could some one give insight why this work around is required?
I also run into the same issue when trying to create a computed property like this.
imagesSelected () {
return this.$refs.myDropzone.getAcceptedFiles().length > 0
},
Is there a better way I'm missing?
For some reason,
setOptionmethod doesn't work, as a workaround, I used this brute force approach:mounted () { setTimeout(() => { this.$refs.myVueDropzone.dropzone.options.url = this.uploadUrl this.$refs.myVueDropzone.dropzone.options.headers = {Authorization: `bearer ${this.token}`} }, 0); }
uploadUrlandtokenare computed propertiesyou saved my day!
This works for me, thanks!!!!