vue front-end copy content to clipboard

Implement front-end copying content to clipboard without using plug-ins

//methods
  handleCopyContent (content) {
      var input = document.createElement('input') // 创建input对象
      input.value = content // 设置复制内容
      document.body.appendChild(input) // 添加临时实例
      input.select() // 选择实例内容
      document.execCommand('Copy') // 执行复制
      document.body.removeChild(input) // 删除临时实例
      this.$message.success('已将查询结果复制到剪切板!')
    },
this.handleCopyContent(this.queryRes)  //调用  可以是点击按钮 传入内容

Very simple and clear.

Guess you like

Origin blog.csdn.net/Yoga99/article/details/127529511