vue-dropzone icon indicating copy to clipboard operation
vue-dropzone copied to clipboard

setOption not working

Open bitnosis opened this issue 7 years ago • 8 comments

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.

bitnosis avatar Oct 05 '18 20:10 bitnosis

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)

rowanwins avatar Oct 05 '18 21:10 rowanwins

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??

bitnosis avatar Oct 06 '18 17:10 bitnosis

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?

rowanwins avatar Oct 13 '18 08:10 rowanwins

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

mabdalmoniem avatar Jan 15 '19 06:01 mabdalmoniem

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

you saved my day!

ahmedsayedabdelsalam avatar Feb 23 '20 14:02 ahmedsayedabdelsalam

@mabdalmoniem your smile made my day <3

hashemfathy avatar Feb 23 '20 14:02 hashemfathy

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?

michaeltoohig avatar Apr 26 '20 01:04 michaeltoohig

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

you saved my day!

This works for me, thanks!!!!

chandanb007 avatar Jun 17 '20 11:06 chandanb007