-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add an example Vue integration.md (#5899)
* Create vue.md Instructions for Vue integration (based on React example). * Add link to Vue guide
- Loading branch information
1 parent
511f729
commit 4c277fd
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Video.js and Vue integration | ||
|
||
Here's a basic Vue player implementation. | ||
|
||
It just instantiates the Video.js player on `mounted` and destroys it on `beforeDestroy`. | ||
|
||
```vue | ||
<template> | ||
<div> | ||
<video ref="videoPlayer" class="video-js"></video> | ||
</div> | ||
</template> | ||
<script> | ||
import videojs from 'video.js'; | ||
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> | ||
``` | ||
|
||
You can then use it like this: (see [options guide][options] for option information) | ||
|
||
```vue | ||
<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" | ||
} | ||
] | ||
} | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
Don't forget to include the Video.js CSS, located at `video.js/dist/video-js.css`. | ||
|
||
[options]: /docs/guides/options.md |