Refactor copy util with Web API (#432)

This commit is contained in:
Fine0830 2024-11-24 17:25:13 +08:00 committed by GitHub
parent aff69c057f
commit 5c92a46569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,18 +16,22 @@
*/ */
import { ElNotification } from "element-plus"; import { ElNotification } from "element-plus";
export default (value: string): void => {
const input = document.createElement("input"); export default (text: string): void => {
input.value = value; navigator.clipboard
document.body.appendChild(input); .writeText(text)
input.select(); .then(() => {
if (document.execCommand("Copy")) { ElNotification({
document.execCommand("Copy"); title: "Success",
} message: "Copied",
input.remove(); type: "success",
ElNotification({ });
title: "Success", })
message: "Copied", .catch((err) => {
type: "success", ElNotification({
}); title: "Error",
message: err,
type: "warning",
});
});
}; };