在使用uniapp开发微信H5中,出现的灵异bug,在使用uniapp的uni.setClipboardData时,IOS设备没有问题,安卓设备中出现复制之后,切到后台,重新返回页面时,列表回滚到顶部问题。
索性不使用setClipboardData
使用下面方法解决问题,都快自闭了,终于解决了
function copyTextToClipboard(text) {
var textArea = document.createElement(“textarea”)
textArea.style.position = ‘fixed’
textArea.style.top = 0
textArea.style.left = 0
textArea.style.width = ‘2em’
textArea.style.height = ‘2em’
textArea.style.padding = 0
textArea.style.border = ‘none’
textArea.style.outline = ‘none’
textArea.style.boxShadow = ‘none’
textArea.style.background = ‘transparent’
textArea.value = text
document.body.appendChild(textArea)
textArea.select()
try {
var msg = document.execCommand(‘copy’) ? ‘成功’ : ‘失败’
alert(‘复制’ + msg);
} catch (err) {
alert(‘不能使用这种方法复制’);
}
document.body.removeChild(textArea)
}