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

Error in directive clipboard unbind hook

Open whity opened this issue 6 years ago • 7 comments

Hello,

When the component is destroyed, I'm getting the following error:

Error in directive clipboard unbind hook: "TypeError: Cannot read property 'destroy' of undefined"

Thanks.

whity avatar Oct 29 '19 14:10 whity

FWIW, I have the same issue. It doesn't seem to matter how the button is removed from the DOM (v-if or a route change), it always results in the same error.

cliffrowley avatar Nov 05 '19 13:11 cliffrowley

+1, I cannot seem to figure out root cause but I am now gutting this package from my project.

kevin-daniel-hunt avatar Nov 08 '19 19:11 kevin-daniel-hunt

https://github.com/Inndy/vue-clipboard2#sample-2 use this method - and you will don't have issues

Alex-Golovin avatar Dec 26 '19 20:12 Alex-Golovin

My team can confirm this is still an issue when the component is destroyed. You get a slightly better log from firefox: 'Error in directive clipboard unbind hook: "TypeError: el._vClipboard is undefined"'. It would be nice to have the directives working but we can confirm sample2 also works.

BryceV avatar May 08 '20 19:05 BryceV

+1 same problem here

Daniel4Digital avatar May 21 '21 16:05 Daniel4Digital

For what I checked, when the component is loaded with the directives it fires the copy directive.

So instead of firing bind first, it will on some ocasions run unbind first. When that happen the binding.args have 'copy'. And it bugs on the last else else { el._vClipboard.destroy() delete el._vClipboard }

So, to quickly fix this we just need to add if(!el._vClipboard) return

On the first line of the unbind hook.

PS: This still needs more deep investigation. But at least that would solve this.

best regards

Daniel4Digital avatar May 21 '21 16:05 Daniel4Digital

When is the PR from above will be merged? It solves for me too.

GoncaloNevesCorreia avatar Jun 23 '21 19:06 GoncaloNevesCorreia