video视频播放

1.列表页面

javascript 复制代码
<template>
  <div>
    <ul>
      <li class="item" v-for="(item,index) in list" :key="index" @click="turnPlay(item.videoUrl)">
        <img :src="item.img" alt="">
        <div class="btn">
          <i class="el-icon-caret-right"></i>
        </div>
        <div class="mask">一行白鹭上青天一行白鹭上青天一行白鹭上青天</div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data () {
    return {
      list: [
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        },
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        },
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        },
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        },
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        },
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        },
        {
          img: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.png',
          videoUrl: 'https://oss.ncsis.org.cn:9000/test/龙年拜年.mp4'
        }
      ]
    }
  },
  methods: {
    turnPlay (url) {
      window.open(`${window.location.origin}/#/playVideo?url=${url}`, '_blank')
    }
  }
}
</script>

<style lang="less" scoped>
ul {
  display: flex;
  padding: 20px;
  flex-wrap: wrap;
  border: 1px solid red;
  box-sizing: border-box;
  justify-content: space-between;
  li {
    width: calc(90% / 6);
    height: 240px;
    overflow: hidden;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      transition: all 1s ease 0s;
      &:hover {
        transform: scale(1.2);
      }
    }
    .btn {
      position: absolute;
      top: 100px;
      left: 50%;
      width: 40px;
      height: 40px;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      transform: translate(-50%, 0);
      .el-icon-caret-right {
        font-size: 30px;
        color: #fff;
      }
    }
    .mask {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 40px;
      background: linear-gradient(transparent 0, rgba(0, 0, 0, 0.75) 100%);
      line-height: 40px;
      padding: 0 5px 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: #fff;
    }
  }
}
</style>

2.视频页面

javascript 复制代码
<template>
  <div class="content">
    <div class="item">
      <div class="title">{{title}}</div>
      <video width="1080" v-if="url" ref="videoRef" height="550" controlsList="nodownload" preload poster="" controls class="video">
        <source :src="url" type="video/mp4">
      </video>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      title: '一行白鹭上青天',
      url: ''
    }
  },
  created () {
    this.url = this.$route.query.url
  },
  mounted () {
    if (this.url) {
      this.$refs.videoRef.play()
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  width: 100%;
  height: 100vh;
  background: #1b1b1b;
  display: flex;
  align-items: center;
  justify-content: center;
  .item {
    display: flex;
    flex-direction: column;
  }
}
</style>

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

相关推荐
东东516几秒前
OA自动化居家办公管理系统 ssm+vue
java·前端·vue.js·后端·毕业设计·毕设
周某人姓周4 分钟前
DOM型XSS案例
前端·安全·web安全·网络安全·xss
程序员鱼皮15 分钟前
前特斯拉 AI 总监:AI 编程最大的谎言,是 “提效”
前端·后端·ai·程序员·开发
Irene199123 分钟前
Vue3 规范推荐的 <script setup> 中书写顺序(附:如何响应路由参数变化)
vue.js·路由
却道天凉_好个秋24 分钟前
音视频学习(八十七):AVCC、HVCC和VVCC
音视频·avcc·hvcc·vvcc
pusheng202527 分钟前
普晟传感2026年新春年会总结与分析
前端·javascript·html
谢尔登28 分钟前
React19事件调度的设计思路
前端·javascript·react.js
Emma_Maria38 分钟前
本地项目html和jquery,访问地址报跨域解决
前端·html·jquery
奋斗吧程序媛43 分钟前
常用且好用的命令
前端·编辑器
2301_796512521 小时前
【精通篇】打造React Native鸿蒙跨平台开发高级复合组件库开发系列:Lazyload 懒加载(懒加载的图片)
前端·javascript·react native·react.js·ecmascript·harmonyos