it-tools/src/composable/copy.ts

15 lines
388 B
TypeScript
Raw Normal View History

import { useClipboard, type MaybeRef } from '@vueuse/core';
2022-04-04 00:24:45 +02:00
import { useMessage } from 'naive-ui';
export function useCopy({ source, text = 'Copied to the clipboard' }: { source: MaybeRef<string>; text?: string }) {
2022-04-04 00:24:45 +02:00
const { copy } = useClipboard({ source });
const message = useMessage();
return {
async copy() {
await copy();
message.success(text);
},
};
}