Vue使用video.js的代碼詳解
一、下載video.js
npm install --save-dev video.js
二、在vue腳手架中引入video.js(main.js引入)
import Video from 'video.js' import 'video.js/dist/video-js.css' Vue.prototype.$video = Video //引入Video播放器
三、實例化了視頻.js播放器,并在 上銷毀了它
<template> <div> <video ref="videoPlayer" class="video-js"></video> </div> </template> <script> import videojs from 'video.js'; //不要忘記包括視頻.js CSS,位于 .<code>video.js/dist/video-js.css</code> export default { name: "VideoPlayer", props: { options: { type: Object, default() { return {}; } } }, data() { return { player: null } }, mounted() { this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() { console.log('onPlayerReady', this); }) }, beforeDestroy() { if (this.player) { this.player.dispose() } } } </script>
三、組件使用video.js
<template> <div> <video-player :options="videoOptions"/> </div> </template> <script> import VideoPlayer from "@/components/VideoPlayer.vue"; export default { name: "VideoExample", components: { VideoPlayer }, data() { return { videoOptions: { autoplay: true, controls: true, sources: [ { src: "/path/to/video.mp4", type: "video/mp4" } ] } }; } };
到此這篇關(guān)于Vue使用video.js的代碼詳解的文章就介紹到這了,更多相關(guān)vue使用video.js內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue項目中v-model父子組件通信的實現(xiàn)詳解
vue.js,是一個構(gòu)建數(shù)據(jù)驅(qū)動的 web 界面的庫。Vue.js 的目標是通過盡可能簡單的 API 實現(xiàn)響應的數(shù)據(jù)綁定和組合的視圖組件。下面這篇文章主要給大家介紹了關(guān)于vue項目中v-model父子組件通信實現(xiàn)的相關(guān)資料,需要的朋友可以參考下。2017-12-12Vue3 封裝 element-plus 圖標選擇器實現(xiàn)步驟
這篇文章主要介紹了Vue3 封裝 element-plus 圖標選擇器,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09ant design Vue 純前端實現(xiàn)分頁問題
這篇文章主要介紹了ant design Vue 純前端實現(xiàn)分頁問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04Vue中.env、.env.development及.env.production文件說明
這篇文章主要給大家介紹了關(guān)于Vue中.env、.env.development及.env.production文件說明的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家學習或者使用vue具有一定的參考學習價值,需要的朋友可以參考下2022-09-09Vue.js遞歸組件實現(xiàn)組織架構(gòu)樹和選人功能
這篇文章主要介紹了Vue.js遞歸組件實現(xiàn)組織架構(gòu)樹和選人功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07Vue數(shù)據(jù)增刪改查與表單驗證的實現(xiàn)流程介紹
這篇文章主要介紹了Vue數(shù)據(jù)增刪改查與表單驗證的實現(xiàn),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-10-10