Inndy / vue-clipboard2

A simple vue2 binding to clipboard.js
https://vue-clipboard2.inndy.tw/
MIT License
1.77k stars 242 forks source link

not work on vuetify dialog #98

Open jazuly opened 3 years ago

jazuly commented 3 years ago

im not sure but when i try, it not work on vuetify dialog

billerby commented 3 years ago

Having the same issue since a while back. Which version of vuetify are you on?

jazuly commented 3 years ago

the latest one..

billerby commented 3 years ago

Well this is fixed in #23 you have to provide a container to make it work on modals.

orkhan-huseyn commented 3 years ago

Use container option if you're inside Vuetify dialog.

const container = document.querySelector('.v-dialog');

this.$copyText('Your text here', container).then(() => {
     this.snackbar = true;
});
ziqq commented 3 years ago

Use this config, it's work.

import VueClipboard from 'vue-clipboard2';
VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);
alfreema commented 3 years ago

Use container option if you're inside Vuetify dialog.

const container = document.querySelector('.v-dialog');

this.$copyText('Your text here', container).then(() => {
     this.snackbar = true;
});

This worked for me. I am able to use a v-btn inside a v-dialog, and the contents of the clipboard are correct when I paste into a text doc.

Use this config, it's work.

import VueClipboard from 'vue-clipboard2';
VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);

This did not. My v-btn inside the v-dialog fires, the $copyText function fires, but the clipboard does not get updated.

renatodeleao commented 3 years ago

Looking at the source, the option autoSetContainer is only passed down to vue directive not to the instance prototype function $copyText.

https://github.com/Inndy/vue-clipboard2/blob/8a542c558c6857212d06f6fc1929384a5b5104cc/vue-clipboard.js#L3-L18

This makes sense, because as an imperative API, it seems to me that you can't infer the container automagically, since the function can be called anywhere — EDIT: that being said, documentation could explicit about it.

So in addendum to @alfreema @orkhan-huseyn answers for the container option:

Cheers!

Microhawk commented 3 years ago

If the parent component is a "v-dialog", maybe you can add a tag like " copySelect=".v-dialog"" in the parent component, then pass the value to the child component. In the child component, code likes the follow. `let container = document.querySelector(this.copySelect);

this.$copyText('Your text', container).then(() => { });`