2022.8.9 - 剪贴板操作 Clipboard API 教程

阮一峰老师教程:https://www.ruanyifeng.com/blog/2021/01/clipboard-api.html

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',
    });
}
posted @ 2022-08-09 19:17  吕业浩  阅读(144)  评论(0)    收藏  举报