当前位置:编程学习 > JS >>

vue实现点击复制的代码

<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> 
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,