File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { ref } from 'vue' ;
2
+
3
+ export type UseClipboardOptions = {
4
+ source : string ;
5
+ } ;
6
+
7
+ export function useClipboard ( { source } : UseClipboardOptions ) {
8
+ const copied = ref ( false ) ;
9
+
10
+ const copy = async ( ) => {
11
+ try {
12
+ await navigator . clipboard . writeText ( source ) ;
13
+ copied . value = true ;
14
+ setTimeout ( ( ) => {
15
+ copied . value = false ;
16
+ } , 300 ) ;
17
+ } catch ( err ) {
18
+ console . error ( '[vue-json-pretty] Copy failed: ' , err ) ;
19
+ }
20
+ } ;
21
+
22
+ return {
23
+ copy,
24
+ } ;
25
+ } ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ type UseErrorOptions = {
4
4
emitListener : boolean ;
5
5
} ;
6
6
7
- export default function useError ( message : string , { emitListener } : UseErrorOptions ) {
7
+ export function useError ( message : string , { emitListener } : UseErrorOptions ) {
8
8
const emit = ( ) => {
9
9
throw new Error ( `[VueJsonPretty] ${ message } ` ) ;
10
10
} ;
You can’t perform that action at this time.
0 commit comments