copy (data) {
const input = document.createElement(‘input’)
input.setAttribute(‘readonly’, ‘readonly’) // 设置只读,不拉起键盘
input.setAttribute(‘value’, data)
document.body.appendChild(input)
input.select() // 不用focus()聚集,直接选择input所有内容
input.setSelectionRange(0, input.value.length)
// 除ios环境外,其他环境使用select()就能够复制input的内容
let res = document.execCommand(‘copy’, true)
if (res) {
this.KaTeX parse error: Expected 'EOF', got '}' at position 21: …('复制成功') }̲ else { …toast(‘复制失败,请重试’)
}
document.body.removeChild(input)
},
复制到粘贴板
最新推荐文章于 2023-03-31 16:16:29 发布