vue+elementui+springboot实现弹框播放视频

本文介绍如何使用Vue结合ElementUI及SpringBoot实现视频列表展示与弹框播放功能。通过前端交互获取视频类型并请求后端获取视频列表,点击播放按钮后在弹窗中播放视频。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


一、vue+elementui+springboot实现弹框播放视频

1.演示效果:

点击play按钮,实现视频播放。在这里插入图片描述
在这里插入图片描述

二、前端代码

代码如下:

<template>
  <div >
  <div style="margin: 10px 0">
      <el-input v-model="type" placeholder="please enter video type" style="width: 20%" clearable></el-input>
      <el-button type="primary" style="margin-left: 5px" @click="getbytype">select</el-button>
  </div>
   <el-table v-loading="loading" :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="id" width="200"> </el-table-column>
    <el-table-column prop="videoname" label="videoname" width="300"> </el-table-column>
    <el-table-column prop="type" label="video type" width="240"> </el-table-column>
    <el-table-column prop="time" label="video time" width="240"> </el-table-column>
    <el-table-column prop="videoURL" label="operation" align="center"  width="240">
	    <template #default="scope">
	            <div v-if="scope.row.videoURL">
	              <el-button type="success" plain @click="playVideo(scope.row.videoURL)"  ref="btn" size="mini" > play</el-button>
	            </div>
	    </template>
    </el-table-column>

  </el-table>
     <el-dialog
      title="视频预览"
      :visible.sync="dialogPlay"
      v-model="dialogPlay"
      width="30%"
      @close="closeDialog"
    >
 
     <video   
        :src= "videoUrl"
        controls
        autoplay
        class="video"
        ref="dialogVideo"
        width="352" 
        height="264"
      ><source type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'></video>
    </el-dialog> 
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  name: "Video",
  data() {
    return {
      tableData: [],
      loading: true,
      dialogPlay: false,
      videoUrl: "",
      type: '',
    }
  },
    created () {
    this.loading = true
       request.get("/video/videolist")
        .then(res => {
            this.tableData = res
            this.loading = false
          },
          res => {
            console.log("error");
            alert("请求失败");
          }
        );
  },
  methods: {
     // 视频
    playVideo(url) {
      this.dialogPlay = true;
      this.videoUrl = require('../assets/'+url);
    },
    closeDialog() {
      this.videoUrl = ""; //清空数据 关闭视频播放
    },
    getbytype() {
        request.get("/video/getbytype", {
        params: {
          type: this.type
        }
      }).then(res => {
        this.tableData = res.data
      })
    }

  }
}
</script>

三、后端代码

package com.example.platform.controller;

import com.example.platform.common.Result;
import com.example.platform.mapper.VideoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    JdbcTemplate jct;

    @Resource
    VideoMapper videoMapper;

    @GetMapping("/videolist")
    public List<Map<String, Object>> videoList(){
        String sql = "select * from video";
        List<Map<String, Object>> map = jct.queryForList(sql);
        return map;
    }
    @RequestMapping("/getbytype")
    public Result<?> getBytype(@RequestParam(value="type") String type) {
        System.out.println(type);
        return Result.success(videoMapper.selectbytype(type));
    }
}

总结

简单记录一下代码。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值