index.vue 935 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div>
  3. <video ref='plyr'
  4. class='c-plyr'
  5. :style="!isFull ? {'width': width+'px','height': height+'px'} : {}"
  6. controls
  7. autoplay
  8. :src="src"
  9. loop>
  10. </video>
  11. </div>
  12. </template>
  13. <script>
  14. import Plyr from 'plyr'
  15. import 'plyr/dist/plyr.css'
  16. export default {
  17. props: ['width', 'height', 'src'],
  18. data () {
  19. return {
  20. isFull: false
  21. }
  22. },
  23. mounted () {
  24. let plyr = new Plyr(this.$refs.plyr, {
  25. autoplay: true,
  26. muted: true,
  27. })
  28. plyr.on('enterfullscreen', this.enterfullscreen)
  29. plyr.on('exitfullscreen', this.exitfullscreen)
  30. },
  31. watch: {
  32. src (val) {
  33. // console.log(val)
  34. // console.log(this.width, this.height)
  35. }
  36. },
  37. methods: {
  38. enterfullscreen () {
  39. this.isFull = true
  40. },
  41. exitfullscreen () {
  42. this.isFull = false
  43. },
  44. }
  45. }
  46. </script>
  47. <style lang="less" scoped>
  48. </style>