bindCopy(txt) {
                //创建容器
                var div = document.createElement('div');
                div.innerText = txt;
                div.id = 'copy';
                div.style.height=0;
                div.style.opacity=0;
                var bo = document.body; //获取body对象.
                bo.insertBefore(div, bo.lastChild);

                // 创建range对象
                let range = document.createRange();
                // 传入需要选中的节点
                range.selectNodeContents(div);
                var selection = document.getSelection();
                // 清空选中的区域
                selection.removeAllRanges();
                // 添加选中区域
                selection.addRange(range);
                // 执行复制
                document.execCommand('Copy');
                this.$toast('复制成功');
                
                bo.removeChild(div);
            }    

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
相关资源
相似解决方案