<div>
<span ref="copy">复制的内容</span>
<span @click="copyOdd" >复制</span>
</div>
//复制的方法
copyOdd() {
window.getSelection().removeAllRanges();
let copyDOM = this.ref:是要复制的部分内容
let range = document.createRange();
range.selectNode(copyDOM);
window.getSelection().addRange(range);
try {
let successful = document.execCommand("copy");
this.{successful ? "复制成功" : "您的手机不支持自动复制,请手动复制~"}`
);
} catch (err) {
alert(err);
}
window.getSelection().removeAllRanges();
}