1 methods: {
2 copyURL() {
3 var Url = this.$refs.mylink;
4 Url.innerHTML = window.location.href;
5 console.log(Url.innerHTML)
6 Url.select();
7 document.execCommand("copy");
8 }
9 }
10
1 <button @click.prevent="handlerCopyText">
2 <input id="copyText" v-model="copyMessage" type="hidden" />
3 <img src="~/assets/svg/copy-link.svg" alt="" srcset="" class="object-contain max-h-10 mx-auto" />
4 <div class="text-center text-sm text-gray-900">Salin tautan</div>
5 </button>
6
7<script>
8
9 handlerCopyText() {
10 const copyText = document.querySelector('#copyText')
11 copyText.setAttribute('type', 'text')
12 copyText.select()
13
14 const successful = document.execCommand('copy')
15
16 if (successful) {
17 this.copySuccess = successful
18 this.copyMessage = `${window.location.href}`
19 setTimeout(() => {
20 this.copySuccess = false
21 }, 800)
22 }
23
24 copyText.setAttribute('type', 'hidden')
25 window.getSelection().removeAllRanges()
26 }
27
28</script>