nuxt视频如何使用video标签?

参数什么的根据自己的需求调整

<template>
	<!-- <IndexVideo /> -->
	 <div class="video-player">
	     <video ref="videoPlayer" :src='srcurl' muted loop autoplay></video>
	 </div>
</template>
<script>
export default {
    data(){
        return{
            srcurl:''
        }
    },
    mounted() {
        this.srcurl = 'http://vjs.zencdn.net/v/oceans.mp4';
        this.videoPlayer = this.$refs.videoPlayer;
        this.videoPlayer.addEventListener('ended', this.handleVideoEnded);
    },
    beforeDestroy() {
        // Clean up event listener when the component is about to be destroyed
        this.videoPlayer.removeEventListener('ended', this.handleVideoEnded);
    },
    methods:{
        handleVideoEnded() {
            // When the video ends, rewind to the beginning and play again
            this.videoPlayer.currentTime = 0;
            this.videoPlayer.play();
        },
    }
}
</script>
<style scoped lang="scss">

</style>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Nuxt.js is a framework for building Vue.js applications. It provides server-side rendering, routing, and other useful features for developing web applications. Video.js is a popular open-source HTML5 video player library. To use Video.js with Nuxt.js, you can follow these steps: 1. Install the required dependencies by running the following command in your Nuxt.js project: ``` npm install video.js vue-video-player ``` 2. Create a new Vue component for your video player. You can create a file called `VideoPlayer.vue` in your components directory, for example. 3. In the `VideoPlayer.vue` file, import the necessary dependencies: ```javascript <template> <div> <video ref="videoPlayer" class="video-js"></video> </div> </template> <script> import videojs from 'video.js'; import 'video.js/dist/video-js.css'; import 'vue-video-player/src/custom-theme.css'; export default { mounted() { this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() { console.log('Player is ready'); }); }, beforeDestroy() { if (this.player) { this.player.dispose(); } }, data() { return { player: null, options: { // Configure your video player options here }, }; }, }; </script> ``` 4. Now, you can use the `VideoPlayer` component in your Nuxt.js pages or components by importing it and including it in your template: ```javascript <template> <div> <VideoPlayer /> </div> </template> <script> import VideoPlayer from '~/components/VideoPlayer.vue'; export default { components: { VideoPlayer, }, }; </script> ``` Remember to customize the options in the `VideoPlayer` component according to your needs. This is a basic setup to get you started with Video.js in Nuxt.js. You can refer to the official documentation of Nuxt.js and Video.js for more advanced usage and configuration options.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钟Bubble

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值