1
1
<template >
2
- <v-container >
3
- <!-- Displaying the JSON object -->
4
- <v-card max-height =" 600px" class =" overflow-y-auto" >
5
- <pre >{{ JSON.stringify(metrics, null, 2) }}</pre >
6
- </v-card >
7
- </v-container >
2
+ <v-container >
3
+ <!-- Displaying the JSON object -->
4
+ <v-card max-height =" 600px" class =" overflow-y-auto" >
5
+ <pre ref =" jsonText" >{{ JSON.stringify(metrics, null, 2) }}</pre >
6
+ </v-card >
7
+ <br >
8
+ <div class =" copy-container" >
9
+ <v-btn @click =" copyToClipboard" >Copy to Clipboard</v-btn >
10
+ <transition name =" fade" >
11
+ <div v-if =" showCopyMessage" :class =" {'copy-message': true, 'error': isError}" >{{ message }}</div >
12
+ </transition >
13
+ </div >
14
+ </v-container >
8
15
</template >
9
-
10
- <script lang="ts">
11
- import { defineComponent } from ' vue' ;
12
-
13
- export default defineComponent ({
14
- name: ' ApiResponse' ,
15
- props: {
16
- metrics: {
17
- type: Object ,
18
- required: true
19
- }
20
- },
21
16
22
- });
23
- </script >
24
-
25
- <style scoped>
26
- .tiles-container {
27
- display : flex ;
28
- justify-content : flex-start ;
29
- flex-wrap : wrap ;
17
+ <script lang="ts">
18
+ import { defineComponent } from ' vue' ;
19
+
20
+ export default defineComponent ({
21
+ name: ' ApiResponse' ,
22
+ props: {
23
+ metrics: {
24
+ type: Object ,
25
+ required: true
26
+ }
27
+ },
28
+ data() {
29
+ return {
30
+ showCopyMessage: false ,
31
+ isError: false ,
32
+ message : ' '
33
+
34
+ };
35
+ },
36
+ methods: {
37
+ copyToClipboard() {
38
+ const jsonText = this .$refs .jsonText as HTMLElement ;
39
+ navigator .clipboard .writeText (jsonText .innerText )
40
+ .then (() => {
41
+ this .message = ' Copied to clipboard!' ;
42
+ this .isError = false ;
43
+ })
44
+ .catch (err => {
45
+ this .message = ' Could not copy text!' ;
46
+ this .isError = true ;
47
+ console .error (' Could not copy text: ' , err );
48
+ });
49
+
50
+ this .showCopyMessage = true ;
51
+ setTimeout (() => {
52
+ this .showCopyMessage = false ;
53
+ }, 3000 );
54
+ }
30
55
}
31
- </style >
56
+
57
+ });
58
+ </script >
59
+
60
+ <style scoped>
61
+ .tiles-container {
62
+ display : flex ;
63
+ justify-content : flex-start ;
64
+ flex-wrap : wrap ;
65
+ }
66
+ .copy-container {
67
+ display : flex ;
68
+ align-items : center ;
69
+ }
70
+ .copy-message {
71
+ margin-left : 10px ;
72
+ font-family : Roboto, sans-serif ;
73
+ }
74
+ .copy-message.error {
75
+ color : red ;
76
+ }
77
+ .copy-message :not (.error ) {
78
+ color : darkgreen ;
79
+ }
80
+ .fade-enter-active , .fade-leave-active {
81
+ transition : opacity 0.5s ;
82
+ }
83
+ .fade-enter , .fade-leave-to {
84
+ opacity : 0 ;
85
+ }
86
+ </style >
0 commit comments