Open tiantingrui opened 2 years ago
import { ElMessage } from "element-plus"; export const useCopy = (text: string) => { // 1. 创建输入框 let input = document.createElement("input"); // 2. 给输入框 value 赋值 input.value = text; // 3. 追加到 body 里面去 document.body.appendChild(input); // 4. 选择输入框的操作 input.select(); // 5. 执行复制操作 document.execCommand("copy"); // 6. 删除加入的输入框 document.body.removeChild(input); // 7. 提示用户 ElMessage.success("复制成功"); }
前置知识
编写自定义hook - useCopy.ts