Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 复制文案的兼容写法

复制文案的兼容写法

1. 兼容写法

// 兼容写法



async handleCopyUserLink() {
  try {
    // 优先使用现代 API
    await navigator.clipboard.writeText("我是要复制的内容");
    this.$message.success('复制成功');
  } catch (err) {
    // 降级方案(execCommand 已经逐渐被弃用)
    this.$refs.copy.select();
    document.execCommand('copy');
    this.$message.success('复制成功');
  }
}
Edit this page
最近更新: 2025/10/17 02:02
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人