下方会介绍两种方式:
1、选中复制
2、点击复制

选中复制 

<template>
	<el-button type="primary" plain @click="onCopy">复制</el-button>
</template>

<script>
export default {
  methods:{
    onCopy(){
        document.execCommand("Copy"); // 执行浏览器复制命令
        this.$message({
          message: '复制成功',
          type: 'success'
        });
      }
  }
}
</script>

点击复制

<template>
	<el-button type="primary" plain @click="onCopy">复制</el-button>
</template>

<script>
export default {
  methods:{
    onCopy(){
       const url = '我是要被复制的内容'
      let oInput = document.createElement('input')
      oInput.value = url
      document.body.appendChild(oInput)
      oInput.select() // 选择对象;
      document.execCommand('Copy') // 执行浏览器复制命令
      this.$message({
        message: '复制成功',
        type: 'success'
      })
      oInput.remove()
  }
}
</script>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐