<template>
  <div>
    <p>{{ url }}</p>
    <button @click="copy">复制 URL</button>
  </div>
</template>

<script setup>
import { isMobile } from '@/utils/device'
const url = ref('')
if (isMobile()) {
  url.value = window.location.href
}
// 点击复制按钮复制字符串到剪切板
const copy = () => {
  const input = document.createElement('input');
  input.value = url.value;
  document.body.appendChild(input);
  input.select();
  document.execCommand('Copy');
  document.body.removeChild(input);
  alert('复制成功');
}
</script>

<style scoped></style>