xxxxxxxxxx
methods: {
copyURL() {
var Url = this.$refs.mylink;
Url.innerHTML = window.location.href;
console.log(Url.innerHTML)
Url.select();
document.execCommand("copy");
}
}
xxxxxxxxxx
<template>
<button @click="copyMe('Copied')">Copy Your Code</button>
</template>
<script setup>
import { ref } from 'vue'
function copyMe(){
navigator.clipboard.writeText("Copy Clipboard");
}
</script>
xxxxxxxxxx
copyLink(link) {
const el = document.createElement('textarea');
el.value = link;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
}