【发布时间】:2021-11-19 16:57:54
【问题描述】:
在我的 VueJS 应用程序中,我有一个组件可以在单击链接时将基本 URL 复制到剪贴板
<a @click="copyURL" ref="mylink">
<img class="social_icon" src="/images/game/copy-fr.png" alt="Copy icon"
/></a>
<input type="text" class="copyurl_txt" v-model="base" ref="text" />
<div v-if="flash" v-text="flash"></div>
我的脚本中有以下方法,
copyURL() {
this.$refs.text.select();
document.execCommand("copy");
this.flash = "lien copié dans le presse-papiers";
},
这在我的 Firefox 浏览器上运行良好,但在我的 Chrome 上这不会将链接复制到剪贴板...
【问题讨论】:
-
你可以试试这个
navigator.clipboard.writeText(this.$refs.text)w3schools.com/howto/howto_js_copy_clipboard.aspdeveloper.mozilla.org/en-US/docs/Web/API/Clipboard/…