0
On the return of a request is coming the digitable line of a boleto and assign this digitable line to a variable, but what I want to do now is copy this digitable line to the clipboard, so that the user can paste(Ctrl + V) anywhere else.
I’ve found several examples I pure JS, but in the project in question is being used Vuejs and I found nothing to help me.
Example in pure JS:
var copyTextareaBtn = document.querySelector('.copiar');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('.textarea');
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'sim!' : 'não!';
alert('Texto copiado? ' + msg);
} catch (err) {
alert('Opa, Não conseguimos copiar o texto, é possivel que o seu navegador não tenha suporte, tente usar Crtl+C.');
}
});
There is a way for me to use the code above in Vuejs??
Note: original link of the code of the above example here
I tried the code you made above, however it is giving error:
copyTextarea.select() is not a function
, can it be the Quasar Framework interfering?? I saw that it adds severaldiv
's in HTML...– LeonardoEbert
Yes, in my case I put
ref="linhaDigitavel"
both in HTML and function– LeonardoEbert
It’s just like that inside the function
– LeonardoEbert
https://jsfiddle.net/capha10u/
– LeonardoEbert
The problem is that I am not only using Vue, but Quasar, which greatly alters the HTML of Vue, but I will give a complement there...
– LeonardoEbert
Let’s go continue this discussion in chat.
– LeonardoEbert