1. 程式人生 > >Vue —— 復制文本

Vue —— 復制文本

ext comm 成功 document value http href range lec

copyText() {
    const input = document.createElement("input");
    input.setAttribute("readonly", "readonly");
    input.setAttribute("value", "hello world");
    document.body.appendChild(input);
    input.setSelectionRange(0, 9999);
    if (document.execCommand("copy")) {
        document.execCommand("copy");
        console.log("復制成功");
    }
    document.body.removeChild(input);
}

鏈接:https://www.jb51.net/article/135605.htm

Vue —— 復制文本