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


一、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));
    }
}

总结

简单记录一下代码。

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
实现动态路由需要在前端和后端两个方面进行处理,以下是使用VueElementUISpring Boot实现动态路由的代码示例: 前端代码示例: 1. 在Vue中,可以使用Vue Router来处理路由。首先需要在main.js中引入Vue Router并创建router实例,然后在路由配置文件中定义路由。在路由配置文件中,可以使用动态路由参数(例如:id)来处理动态路由: ```javascript // main.js import Vue from 'vue' import VueRouter from 'vue-router' import App from './App.vue' import router from './router' Vue.use(VueRouter) new Vue({ router, render: h => h(App) }).$mount('#app') // router.js import VueRouter from 'vue-router' import Home from './views/Home.vue' import About from './views/About.vue' import Dynamic from './views/Dynamic.vue' const router = new VueRouter({ routes: [ { path: '/', name: 'home', component: Home }, { path: '/about', name: 'about', component: About }, { path: '/dynamic/:id', name: 'dynamic', component: Dynamic } ] }) export default router ``` 2. 在ElementUI中,可以使用Menu组件来实现动态路由。首先需要在App.vue中引入Menu组件,并在Menu组件中定义路由菜单。在路由菜单中,可以使用动态路由参数(例如:id)来处理动态路由: ```html <template> <div id="app"> <el-container> <el-aside> <el-menu :default-active="activeIndex" class="el-menu-vertical-demo" @select="handleSelect"> <el-menu-item index="/"> <i class="el-icon-menu"></i> <span>Home</span> </el-menu-item> <el-menu-item index="/about"> <i class="el-icon-document"></i> <span>About</span> </el-menu-item> <el-menu-item v-for="item in dynamicRoutes" :key="item.path" :index="item.path"> <i class="el-icon-folder"></i> <span>{{ item.name }}</span> </el-menu-item> </el-menu> </el-aside> <el-main> <router-view></router-view> </el-main> </el-container> </div> </template> <script> import { Menu } from 'element-ui' export default { name: 'App', components: { 'el-menu': Menu }, data() { return { activeIndex: '/', dynamicRoutes: [] } }, created() { this.dynamicRoutes = [ { path: '/dynamic/1', name: 'Dynamic1' }, { path: '/dynamic/2', name: 'Dynamic2' } ] }, methods: { handleSelect(index) { this.activeIndex = index this.$router.push(index) } } } </script> ``` 后端代码示例: 1. 在Spring Boot中,可以使用@RestController注解来定义控制器,并在控制器中定义动态路由。在动态路由中,可以使用@PathVariable注解来处理动态

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值