vue 复制文本
copyTXT() {
const dom = document.getElementById(`codeTxt`);
const selection = window.getSelection();
const range = document.createRange();
if (!dom || !selection || !range) return;
// 选择复制目标
range.selectNodeContents(dom);
selection.removeAllRanges();
selection.addRange(range);
// 已复制文字
console.log("selectedText", selection.toString());
// 执行复制
document.execCommand("copy");
this.$toast("复制成功");
// 去除所有选中
selection.removeAllRanges();
// 复制内容成功,通过ctrl+v粘贴使用!
},

浙公网安备 33010602011771号