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