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

Loading…
Cancel
Save