export function copyText(text) {
if (navigator.clipboard?.writeText && window.isSecureContext) {
navigator.clipboard.writeText(text)
} else {
let input = document.createElement("textarea")
// input = document.createElement("input")
input.setAttribute("readonly", "readonly")
input.value = text
document.body.appendChild(input)
input.select()
if (document.execCommand("copy")) document.execCommand("copy")
document.body.removeChild(input)
}
}
这个函数在pc端可以进行异步操作,在手机端不能进行异步操作。
异步操作 比如:我请求一个接口之后我再调用这个剪贴板的函数
必须在点击之后立即使用这个剪贴板接口

Comments | NOTHING