const copy = (text:string) => {
//移动端适配不好
navigator.clipboard?.writeText(text)
.then(function () {
alert('已复制')
}).catch((err)=>{
alert('复制失败,请手动复制')
})
}
移动端建议使用
const copy = (text:string) => {
const input = document.createElement('input')
input.value = text
document.body.appendChild(input)
input.select()
input.setSelectionRange(0, input.value.length)
document.execCommand('Copy')
document.body.removeChild(input)
alert({ content: '已复制' })
}