2022.8.9 - 剪贴板操作 Clipboard API 教程
阮一峰老师教程:https://www.ruanyifeng.com/blog/2021/01/clipboard-api.html
navigator.clipboard(新的API)
async function getClipboardContents(text) {
let textConent = text;
try {
await navigator.clipboard.writeText(textConent);
} catch (err) {
console.error('读取剪贴板内容失败: ', err);
}
}
document.execCommand('Copy')(web标准废弃)
function handleCopy(row) {
if (navigator.clipboard) {
getClipboardContents(row.token);
} else {
let oInput = document.createElement('input');
oInput.value = row.token;
document.body.appendChild(oInput);
oInput.select();
document.execCommand('Copy');
oInput.remove();
}
ElMessage({
message: '复制成功',
type: 'success',
});
}

浙公网安备 33010602011771号