converting songs to new vue3 syntax. Adding copy/paste buttons

practiced-songs
Matthew Huntington 11 months ago
parent 00d43e9bc3
commit cc9542b3a9

@ -1,25 +1,19 @@
<script lang="ts"> <script setup>
import axios from 'axios'; import { onMounted, ref } from 'vue'
export default { const songs = ref([])
data() {
return { onMounted(async ()=>{
songs:[] const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'songs')
} songs.value = await response.json()
},
mounted() {
axios.get(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'songs').then((response)=>{
this.songs = response.data
}) })
}, const copy = (title) => {
methods: { navigator.clipboard.writeText(title);
copy(event){
navigator.clipboard.writeText(event.target.innerText);
} }
}, const paste = (title) => {
alert(title)
} }
</script> </script>
<template> <template>
<h2>Songs</h2> <h2>Songs</h2>
<table> <table>
@ -33,12 +27,13 @@
<tbody> <tbody>
<tr v-for="song in songs"> <tr v-for="song in songs">
<td>{{song.id}}</td> <td>{{song.id}}</td>
<td @click="copy">{{song.title}}</td> <td>
{{song.title}}
<button @click="copy(song.title)">Copy</button>
<button @click="paste(song.title)">Paste</button>
</td>
<td>{{song.notes}}</td> <td>{{song.notes}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</template> </template>
<style scoped>
</style>

Loading…
Cancel
Save