This commit is contained in:
2026-01-01 00:13:50 +08:00
parent 179f1e1f31
commit 87c2d29079
8 changed files with 453 additions and 19 deletions

View File

@@ -0,0 +1,18 @@
/**
* 点击触发元素时,将文本复制到剪贴板,并在触发元素上显示提示信息。
* @param target - 提供复制文本、目标元素或组件实例。可为字符串、输入框(复制其 `value`)或其他 HTMLElement复制其文本内容
*/
export default function useCopy(
target: MaybeRefOrGetter<{ $el: Element } | HTMLInputElement | Element | null> | string,
) {
const getEl = (element: any) => element?.$el ?? element;
const getText = () => {
const el = getEl(toValue(target));
if (typeof target === "string") return target;
if (el instanceof HTMLInputElement) return el.value;
return (el?.textContent as string) || "";
};
return useClipboard({ source: getText, legacy: true });
}