H5 移動端實現復制功能


Template:

<el-button class="btn-close" round type="primary" @click="copyClick">生成並復制</el-button>

methods: 

// 新增一個input標簽,設置其value為復制的內容,再使用execCommand()方法實現復制功能
copyClick () {
  const input = document.createElement('input')
  document.body.appendChild(input)
   input.setAttribute('value',’要復制的內容‘)
  input.select()
  if (document.execCommand('copy')) {
    // IOS不支持此方法,所以復制不成功
    document.execCommand('copy')
  }
  document.body.removeChild(input);
  console.log('復制成功!');
},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM