From ad303096ca46faa8b211c33c41a9c2d4cb66cfb3 Mon Sep 17 00:00:00 2001 From: A1300399510 Date: Thu, 27 Jul 2023 12:12:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=A8=E5=B1=80=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/util.js | 22 +++++++++++++++++----- src/views/user.vue | 5 ++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/utils/util.js b/src/utils/util.js index 29c16a5..0377deb 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -20,11 +20,23 @@ function goTologin() { function copyToClipboard(text) { return new Promise((resolve, reject) => { - navigator.clipboard.writeText(text).then(() => { - resolve() - }).catch((err) => { - reject() - }); + const textareaEle = document.createElement("textarea"); + document.body.appendChild(textareaEle); + // 2. 将需要复制的文本传入输入框, 并调用 select 方法, 选中输入框中文本 + textareaEle.value = text; + textareaEle.select(); + textareaEle.readOnly = 'readOnly'; + // 3. 调用复制选中文本的方法 + document.execCommand('copy'); + // 4. 销毁输入框 + document.body.removeChild(textareaEle); + resolve() + + // navigator.clipboard.writeText(text).then(() => { + // resolve() + // }).catch((err) => { + // reject() + // }); }); } diff --git a/src/views/user.vue b/src/views/user.vue index 43478a1..c1ed9d4 100644 --- a/src/views/user.vue +++ b/src/views/user.vue @@ -37,7 +37,7 @@
发布房源
-