So I am trying to set the src of an element to a js variable and its just not working. I have tried a few ways and I cannot get it to work. Here is one way
<source src="{{ this.show.podcastUrl }}" type="audio/mpeg">
I also tried
<source v-bind:src="{{ this.show.podcastUrl }}" type="audio/mpeg">
And
<source :src="{{ this.show.podcastUrl }}" type="audio/mpeg">
What am I doing wrong? Here is my component
<template>
<div class="panel panel-default">
<div class="panel-heading">
{{ this.show.name }}
<div class="pull-right">
{{ this.show.number }}
</div>
</div>
<div class="panel-body">
<ul>
<li>Air Date: </li>
<li>
<audio controls>
<source v-bind:src="{{ this.show.podcastUrl }}" type="audio/mpeg">
</audio>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
mounted() {
console.log(this.show);
},
props: {
show: {
type: Object,
required: true
}
}
}
</script>
It's because you are using mustaches into v-bind directive - which is not allowed.
Mustaches {{}}
into VueJS are related to templating, v-bind
is passed to JS - so mustaches as part of template engine are not allowed into the v-bind
directive.
This should be correct way:
<source :src="show.podcastUrl" type="audio/mpeg">
Also this
is not needed here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With