【发布时间】:2017-01-14 14:53:37
【问题描述】:
我正在使用 vue-youtube-embed 在我的 vuejs 组件中使用 Youtube API。
这是我的代码:
<script>
export default {
data() {
return {
videoId: 'HjxYvcdpVnU',
videoLaunched: false,
videoLoaded: false,
videoRewatch: false,
videoEnded: false
}
},
computed: {
videoThumb: function () {
return 'https://img.youtube.com/vi/' + this.videoId + '/maxresdefault.jpg';
}
},
methods: {
launchVideo() {
this.videoLaunched = true;
this.player.playVideo();
document.getElementsByTagName('body')[0].classList.add('overlay');
},
ready(player) {
fitvids();
this.player = player;
this.videoLoaded = true;
},
ended() {
console.log('Ended');
}
}
}
</script>
和html:
<youtube :video-id="videoId" @ready="ready" @ended="ended" player-width="100%"
player-height="57" :player-vars="{ autoplay: 0, controls: 1, modestbranding: 1, showinfo: 0, rel: 0 }">
</youtube>
end() 方法没有触发,我不知道为什么。
ready() 方法工作正常,所以我不确定为什么在 end() 方法上没有触发 console.log。
我看不到文档中有关如何操作的示例。
【问题讨论】:
-
我不知道如何回答你的问题,但你知道
body元素可以通过doument.body访问吗?可能会帮助您编写更少的代码。 -
@jeerbl 好提示。谢谢。
标签: javascript youtube-api vue.js youtube-javascript-api vuejs2