File tree Expand file tree Collapse file tree 2 files changed +10
-20
lines changed
Expand file tree Collapse file tree 2 files changed +10
-20
lines changed Original file line number Diff line number Diff line change 11<script setup>
2+ import { useClipboard } from ' @vueuse/core'
3+
24const pkg = useState (' badge-pkg' , () => ' nuxt' )
35const type = useState (' badge-type' , () => ' version' )
46const isValid = ref (true )
5- const copied = ref (false )
7+
8+ const { copy , copied } = useClipboard ({ copiedDuring: 2000 })
69
710const types = [
811 ' version' ,
@@ -42,15 +45,7 @@ const formatLabel = str => {
4245
4346const copyToClipboard = async () => {
4447 const markdown = ` [](https://npmx.dev/package/${ pkg .value } )`
45- try {
46- await navigator .clipboard .writeText (markdown)
47- copied .value = true
48- setTimeout (() => {
49- copied .value = false
50- }, 2000 )
51- } catch {
52- console .error (' Failed to copy to clipboard' )
53- }
48+ copy (markdown)
5449}
5550 </script >
5651
Original file line number Diff line number Diff line change 11<script setup>
2+ import { useClipboard } from ' @vueuse/core'
3+
24const pkg = useState (' badge-pkg' , () => ' nuxt' )
35const type = useState (' badge-type' , () => ' version' )
46const isValid = ref (true )
5- const copied = ref (false )
7+
8+ const { copy , copied } = useClipboard ({ copiedDuring: 2000 })
69
710const labelColor = useState (' badge-label-color' , () => ' ' )
811const labelText = useState (' badge-label-text' , () => ' ' )
@@ -87,15 +90,7 @@ const formatLabel = str => {
8790
8891const copyToClipboard = async () => {
8992 const markdown = ` [](https://npmx.dev/package/${ pkg .value } )`
90- try {
91- await navigator .clipboard .writeText (markdown)
92- copied .value = true
93- setTimeout (() => {
94- copied .value = false
95- }, 2000 )
96- } catch {
97- console .error (' Failed to copy to clipboard' )
98- }
93+ copy (markdown)
9994}
10095< / script>
10196
You can’t perform that action at this time.
0 commit comments