复制文本功能

copyText(){
      const textarea = document.createElement('textarea');
      textarea.readOnly = 'readonly';
      // textarea.style.position = 'absolute';
      // textarea.style.left = '-9999px';
      textarea.value = "文字内容";
      document.body.appendChild(textarea);
      textarea.select();
      textarea.setSelectionRange(0, textarea.value.length);
      const result = document.execCommand('Copy');
      if (result) {
        this.$message.success("复制成功");
      }
      document.body.removeChild(textarea);
}

 

posted @ 2022-07-18 17:27  保洁叔叔  阅读(37)  评论(0编辑  收藏  举报