Skip to content

Commit ea50aed

Browse files
committed
Load src of youtube iframe, when page is loaded
1 parent 443132c commit ea50aed

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
<template>
22
<div>
3-
<iframe type="text/html" width="100%" style="height:100%"
4-
:src="`https://www.youtube.com/embed/${id}`"
5-
frameborder="0" allowfullscreen></iframe>
3+
<iframe
4+
type="text/html"
5+
width="100%"
6+
style="height: 100%"
7+
src=""
8+
frameborder="0"
9+
allowfullscreen
10+
ref="iframe"
11+
></iframe>
612
</div>
713
</template>
814

915
<script setup>
10-
defineProps({
16+
import { onMounted, ref } from "vue";
17+
18+
const props = defineProps({
1119
id: {
1220
type: String,
13-
required: true
14-
}
15-
})
21+
required: true,
22+
},
23+
});
24+
const iframe = ref(null);
25+
26+
onMounted(() => {
27+
window.onload = () => {
28+
if (iframe.value) {
29+
iframe.value.src = `https://www.youtube.com/embed/${props.id}`;
30+
}
31+
};
32+
});
1633
</script>
1734

1835
<style scoped>
1936
div {
2037
background-color: #2c3e50;
2138
width: 100%;
22-
padding-top: min(500px,56%);
39+
padding-top: min(500px, 56%);
2340
position: relative;
2441
border: 3px solid #eaecef;
2542
}
@@ -30,6 +47,5 @@ iframe {
3047
left: 0;
3148
bottom: 0;
3249
right: 0;
33-
3450
}
35-
</style>
51+
</style>

0 commit comments

Comments
 (0)