From f86ce323c82418fcd5cd2bf9203faf8d1602470c Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 24 May 2023 11:44:10 +0800 Subject: [PATCH] =?UTF-8?q?code=E7=BB=84=E4=BB=B6=E7=9A=84=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=8A=9F=E8=83=BD=E5=85=BC=E5=AE=B9=E5=9C=A8http?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=97=B6=E6=97=A0clipboard=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/code/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/code/index.js b/src/code/index.js index ea4f60b..923371b 100644 --- a/src/code/index.js +++ b/src/code/index.js @@ -212,7 +212,18 @@ class Code extends Component { } copyCode() { - navigator.clipboard.writeText(this.code) + if (navigator.clipboard) { + navigator.clipboard.writeText(this.code) + } else { + let ta = document.createElement('textarea') + ta.style.position = 'fixed' + ta.style.left = '-2000px' + ta.value = this.code + this.root.appendChild(ta) + ta.select() + document.execCommand('copy') + ta.remove() + } layer.toast('复制到粘贴板成功', 'success') }