video视频播放

1.列表页面

<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.视频页面

<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’,页面会跳转错误

相关推荐

  1. vue+video-animation-player播放vap视频

    2024-03-10 23:54:01       57 阅读
  2. vue 配合 video.js 实现视频播放

    2024-03-10 23:54:01       30 阅读
  3. CSS video控件去掉视频播放

    2024-03-10 23:54:01       54 阅读
  4. 【Vue3】Vue3使用video-player实现视频播放

    2024-03-10 23:54:01       61 阅读
  5. html 中video实现切换视频自动播放

    2024-03-10 23:54:01       51 阅读
  6. vue-video-play使用之播放hls格式视频

    2024-03-10 23:54:01       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-10 23:54:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-10 23:54:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-10 23:54:01       82 阅读
  4. Python语言-面向对象

    2024-03-10 23:54:01       91 阅读

热门阅读

  1. uniapp——信号值组件(vue3)

    2024-03-10 23:54:01       41 阅读
  2. React-Context机制

    2024-03-10 23:54:01       39 阅读
  3. websocket+心跳

    2024-03-10 23:54:01       47 阅读
  4. uniapp 开发app,如何使用模拟器

    2024-03-10 23:54:01       40 阅读
  5. linux系统安装docker

    2024-03-10 23:54:01       33 阅读
  6. CatBoost高级教程:分布式训练与大规模数据处理

    2024-03-10 23:54:01       38 阅读
  7. Linux运维_Bash脚本_编译安装Mesa-23.3.6(OpenGL)

    2024-03-10 23:54:01       32 阅读
  8. 从零开始 TensorRT(7)C++ 篇:解析 ONNX

    2024-03-10 23:54:01       44 阅读
  9. 云贝福利课程倒计时-Oracle小课

    2024-03-10 23:54:01       32 阅读