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

相关推荐
Bellafu66618 分钟前
selenium 常用xpath写法
前端·selenium·测试工具
superxxd22 分钟前
跨平台音频IO处理库libsoundio实践
开发语言·qt·音视频
blackorbird3 小时前
Edge 浏览器 IE 模式成攻击突破口:黑客借仿冒网站诱导攻击
前端·edge
谷歌开发者4 小时前
Web 开发指向标 | Chrome 开发者工具学习资源 (一)
前端·chrome·学习
名字越长技术越强4 小时前
Chrome和IE获取本机ip地址
前端
天***88964 小时前
Chrome 安装失败且提示“无可用的更新” 或 “与服务器的连接意外终止”,Chrome 离线版下载安装教程
前端·chrome
半梦半醒*4 小时前
zabbix安装
linux·运维·前端·网络·zabbix
清羽_ls4 小时前
React Hooks 核心规则&自定义 Hooks
前端·react.js·hooks
你的人类朋友5 小时前
“签名”这个概念是非对称加密独有的吗?
前端·后端·安全
西陵5 小时前
Nx带来极致的前端开发体验——任务缓存
前端·javascript·架构