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('复制成功!');
},

相关文章:

  • 2022-03-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
相关资源
相似解决方案