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"); // 执行浏览器复制命令 
这种不行
vue中实现浏览器的复制功能

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

 

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

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-11-08
相关资源
相似解决方案