vue element-ui 复制文本到粘贴板

copy(data) {
  let url = data
  let oInput = document.createElement('input')
  oInput.value = url
  document.body.appendChild(oInput)
  oInput.select() // 选择对象
  document.execCommand("Copy") // 执行浏览器复制命令
  this.$message({
    message: '复制成功',
    type: 'success'
  })
  oInput.remove()
}

使用方法

copyLink() {
  this.copy('https://baidu.com/')
}
posted @ 2020-06-22 18:31  lwlcode  阅读(3054)  评论(0编辑  收藏  举报