code组件的复制功能兼容在http访问时无clipboard的情况
parent
7a25bd1ca1
commit
f86ce323c8
|
@ -212,7 +212,18 @@ class Code extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCode() {
|
copyCode() {
|
||||||
|
if (navigator.clipboard) {
|
||||||
navigator.clipboard.writeText(this.code)
|
navigator.clipboard.writeText(this.code)
|
||||||
|
} else {
|
||||||
|
let ta = document.createElement('textarea')
|
||||||
|
ta.style.position = 'fixed'
|
||||||
|
ta.style.left = '-2000px'
|
||||||
|
ta.value = this.code
|
||||||
|
this.root.appendChild(ta)
|
||||||
|
ta.select()
|
||||||
|
document.execCommand('copy')
|
||||||
|
ta.remove()
|
||||||
|
}
|
||||||
layer.toast('复制到粘贴板成功', 'success')
|
layer.toast('复制到粘贴板成功', 'success')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue