vuejs:单击时将标签内容复制到剪贴板而不创建功能
如何在不使用自己的功能的情况下将HTML标签的内容复制到剪贴板?
<div @click="navigator.clipboard.writeText(this)">Hello {{ name }}!</div>
How to copy the content of an html tag to clipboard without using own function?
<div @click="navigator.clipboard.writeText(this)">Hello {{ name }}!</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 > ,通用代码无法假设访问特定于平台的API,因此,如果您的代码直接使用仅浏览器的全球范围,例如
window
或文档
,他们会丢弃错误。因此,常见的方法是懒洋洋地访问仅客户端的生命周期挂钩,例如已安装
。实时演示:
As per the
document
, Universal code cannot assume access to platform-specific APIs, so if your code directly uses browser-only globals likewindow
ordocument
, they will throw errors. Hence, the common approach is to lazily access them inside client-only lifecycle hooks such asmounted
.Live Demo :
我认为在VUE3中,没有“丑陋”解决方案是不可能的,请参阅此处的灵感。但是我认为,最清洁的方法是只用其中一行代码创建一种方法。
I think in Vue3 that is not possible without 'ugly' solutions, see here for inspiration. But I think the cleanest way is to just create a method with that one line of code in it.
更适合可读性
vue;
html;
better for readability
Vue;
Html;