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


  

点击复制,就可以实现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就能行


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM