效果图
HTML代码
<div>链接:
<span style="color: #FF8A21" @click="CopyUrl" id="copyId"> https://blog.csdn.net/qq_51463650?spm=1000.2115.3001.5343</span>
</div>
复制方法
const CopyUrl = () => {
let url = "https://blog.csdn.net/qq_51463650?spm=1000.2115.3001.5343";
if (!url) return showToast('复制失败!')
let copyDom = document.getElementById('copyId')
copyDom.innerText = url
let range = document.createRange()
range.selectNode(copyDom)
window.getSelection().removeAllRanges()
window.getSelection().addRange(range)
let successful = document.execCommand('copy')
if (successful) {
showToast('复制成功!')
} else {
showToast('复制失败!')
}
}