let url = data;
let oInput = document.createElement('input');
oInput.value = url;
document.body.appendChild(oInput);
oInput.select(); // 选择对象;
let text = oInput.value;
if(navigator.clipboard && window.isSecureContext) {
// navigator clipboard 向剪贴板写文本
navigator.clipboard
.writeText(text)
.then(() => {
this.$message({
message: '复制成功',
type: 'success'
});
oInput.remove()
})
.catch(() => {
this.$message({
message: '复制失败',
type: 'error'
});
oInput.remove()
})
}else {
document.execCommand("Copy"); // 执行浏览器复制命令、
this.$message({
message: '复制成功',
type: 'success'
});
oInput.remove()
}
document.execCommand 已弃用 ,navigator.clipboard打印undefined,只有在安全域名下才可以访问(https、localhost),在http域名下只能得到undefined;