首页 > 其他 > 详细

vue中实现浏览器的复制功能

时间:2019-03-04 12:00:33      阅读:313      评论:0      收藏:0      [点我收藏+]

  技术分享图片

点击复制,就可以实现copy

<p class="inline-block">
<span >{{fenxiao.appSecret}}</span>
<span style="color: #0000FF;cursor: pointer" @click="copyAppSecret">复制</span>
</p>

 

copyAppSecret() {
let createInput = document.createElement("input");
createInput.value = this.fenxiao.appSecret;
document.body.appendChild(createInput);
createInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
createInput.style.display = "none";
this.$message({ message: "复制成功", type: "success" });
},

网上说的那种
let tt=document.getElementById("xxxx")
tt.select(); // 选择对象 
 document.execCommand("Copy"); // 执行浏览器复制命令 
这种不行
技术分享图片

文本是没有select方法的,input才有 所以要先创建input元素,在添加值,在赋值,

 

亲测有效,换成el-input就能行

vue中实现浏览器的复制功能

原文:https://www.cnblogs.com/myfirstboke/p/10469584.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!