当前位置:   article > 正文

video视频播放

video视频播放

1.列表页面

  1. <template>
  2. <div>
  3. <ul>
  4. <li class="item" v-for="(item,index) in list" :key="index" @click="turnPlay(item.videoUrl)">
  5. <img :src="item.img" alt="">
  6. <div class="btn">
  7. <i class="el-icon-caret-right"></i>
  8. </div>
  9. <div class="mask">一行白鹭上青天一行白鹭上青天一行白鹭上青天</div>
  10. </li>
  11. </ul>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data () {
  17. return {
  18. list: [
  19. {
  20. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  21. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  22. },
  23. {
  24. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  25. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  26. },
  27. {
  28. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  29. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  30. },
  31. {
  32. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  33. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  34. },
  35. {
  36. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  37. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  38. },
  39. {
  40. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  41. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  42. },
  43. {
  44. img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
  45. videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
  46. }
  47. ]
  48. }
  49. },
  50. methods: {
  51. turnPlay (url) {
  52. window.open(`${window.location.origin}/#/playVideo?url=${url}`, '_blank')
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="less" scoped>
  58. ul {
  59. display: flex;
  60. padding: 20px;
  61. flex-wrap: wrap;
  62. border: 1px solid red;
  63. box-sizing: border-box;
  64. justify-content: space-between;
  65. li {
  66. width: calc(90% / 6);
  67. height: 240px;
  68. overflow: hidden;
  69. border-radius: 6px;
  70. cursor: pointer;
  71. position: relative;
  72. img {
  73. width: 100%;
  74. height: 100%;
  75. object-fit: contain;
  76. transition: all 1s ease 0s;
  77. &:hover {
  78. transform: scale(1.2);
  79. }
  80. }
  81. .btn {
  82. position: absolute;
  83. top: 100px;
  84. left: 50%;
  85. width: 40px;
  86. height: 40px;
  87. background: rgba(0, 0, 0, 0.5);
  88. border-radius: 50%;
  89. display: flex;
  90. align-items: center;
  91. justify-content: center;
  92. transform: translate(-50%, 0);
  93. .el-icon-caret-right {
  94. font-size: 30px;
  95. color: #fff;
  96. }
  97. }
  98. .mask {
  99. position: absolute;
  100. bottom: 0;
  101. left: 0;
  102. width: 100%;
  103. height: 40px;
  104. background: linear-gradient(transparent 0, rgba(0, 0, 0, 0.75) 100%);
  105. line-height: 40px;
  106. padding: 0 5px 0;
  107. overflow: hidden;
  108. text-overflow: ellipsis;
  109. white-space: nowrap;
  110. color: #fff;
  111. }
  112. }
  113. }
  114. </style>

2.视频页面

  1. <template>
  2. <div class="content">
  3. <div class="item">
  4. <div class="title">{{title}}</div>
  5. <video width="1080" v-if="url" ref="videoRef" height="550" controlsList="nodownload" preload poster="" controls class="video">
  6. <source :src="url" type="video/mp4">
  7. </video>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. data () {
  14. return {
  15. title: '一行白鹭上青天',
  16. url: ''
  17. }
  18. },
  19. created () {
  20. this.url = this.$route.query.url
  21. },
  22. mounted () {
  23. if (this.url) {
  24. this.$refs.videoRef.play()
  25. }
  26. }
  27. }
  28. </script>
  29. <style lang="less" scoped>
  30. .content {
  31. width: 100%;
  32. height: 100vh;
  33. background: #1b1b1b;
  34. display: flex;
  35. align-items: center;
  36. justify-content: center;
  37. .item {
  38. display: flex;
  39. flex-direction: column;
  40. }
  41. }
  42. </style>

需要注意我这里跳转页面路由模式是‘hash’,如果是 ‘history’,页面会跳转错误

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/208671
推荐阅读
相关标签
  

闽ICP备14008679号