Skip to content

Commit

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

0 comments on commit 80c8451

Please sign in to comment.