效果图
HTML代码
<div>链接:
<span style="color: #FF8A21" @click="CopyUrl" id="copyId"> https://blog.csdn.net/qq_51463650?spm=1000.2115.3001.5343span>
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('复制失败!')
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23