videoDemo.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="videoDemo" :style="`background-image:url(${require('@/assets/image/background.png')})`">
  3. <video v-if="isPlay" ref="videoDom" width="100%" height="100%" controls muted preload="auto" crossorigin="anonymous">
  4. <source :src="videoSrc" type="video/mp4">
  5. 您的浏览器不支持视频标签。
  6. </video>
  7. <div class="playVideo" v-if="!isPlay" >
  8. <div class="button">
  9. <el-button class="btn" @click="play">播放视频</el-button>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. components: {
  17. },
  18. props: {},
  19. data() {
  20. return {
  21. // videoSrc: require('@/assets/media/yanshi.mp4'),
  22. videoSrc: '',
  23. isPlay:false,
  24. };
  25. },
  26. watch: {},
  27. computed: {},
  28. created() {},
  29. mounted() {
  30. },
  31. methods: {
  32. play(){
  33. this.$message.warning('敬请期待')
  34. return
  35. this.isPlay = true
  36. this.$nextTick(()=>{
  37. console.log(this.$refs.videoDom.play)
  38. this.$refs.videoDom.play()
  39. })
  40. }
  41. },
  42. };
  43. </script>
  44. <style lang="scss" scoped>
  45. .videoDemo{
  46. width: 100%;
  47. height: 100%;
  48. background-size: cover;
  49. background-position: center;
  50. position: relative;
  51. }
  52. .playVideo{
  53. width: 100%;
  54. height: 100%;
  55. position: absolute;
  56. inset: 0;
  57. background-color:rgba(238, 228, 228, 0.2);
  58. }
  59. .button{
  60. width: 80px;
  61. height: 50px;
  62. position: absolute;
  63. inset: 0;
  64. margin: auto;
  65. .btn{
  66. background-color:rgba(238, 228, 228, 0.2);
  67. color: black;
  68. font-weight: bold;
  69. }
  70. }
  71. </style>