Skip to content

Commit

Permalink
Fix AudioPlayer.vue - import audio statically and use dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
shiragold authored Apr 30, 2024
1 parent 80c8451 commit 834ef56
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/content/AudioPlayer.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<script setup>
import { ref, onBeforeMount, onMounted } from 'vue'
import tune from '@media/tune.mp3'
import song from '@media/song.mp3'
const props = defineProps({
src: {
type: String,
required: true
}
})
let audioFile = ref(null)
onBeforeMount(() => audioFile = import('@media/' + props.src + '.mp3'))
onMounted(() => {
document.getElementsByTagName('audio')[0].play()
})
</script>
<template>
<audio>
<source :src="audioFile" type="audio/mpeg" />
<source v-if="src === 'tune'" :src="tune" type="audio/mpeg" />
<source v-if="src === 'song'" :src="song" type="audio/mpeg" />
</audio>
</template>

0 comments on commit 834ef56

Please sign in to comment.