index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view class="login-box">
  3. <view class="video-background">
  4. <video
  5. src="@/static/video/login_bg.mp4"
  6. object-fit="cover"
  7. :autoplay="true"
  8. :controls="false"
  9. :muted="true"
  10. :loop="true"
  11. id="videoRef"
  12. class="video"
  13. @loadedmetadata="videoPlay"
  14. >
  15. </video>
  16. </view>
  17. <login-content v-if="showContent"></login-content>
  18. </view>
  19. </template>
  20. <script>
  21. import LoginContent from "@/pages/login/model/loginContent.nvue";
  22. export default {
  23. components: {LoginContent},
  24. data() {
  25. return {
  26. VideoContext: {},
  27. showContent:false,
  28. isPlay:false
  29. }
  30. },
  31. onLoad(query) {
  32. // #ifdef H5
  33. this.showContent=true
  34. //#endif
  35. },
  36. onShow() {
  37. // 当app切到后台再切回前台的时候会触发onShow这个时候视频应该继续播放,不这样做视频会暂停的
  38. this.$nextTick(() => {
  39. this.videoPlay()
  40. })
  41. },
  42. methods: {
  43. videoPlay(){
  44. this.VideoContext = uni.createVideoContext('videoRef');
  45. this.VideoContext.play()
  46. }
  47. }
  48. }
  49. </script>
  50. <style scoped lang="scss">
  51. .login-box{
  52. position: relative;
  53. height: 100vh;
  54. overflow: hidden;
  55. .video-background{
  56. z-index: 1;
  57. position: absolute;
  58. top: 0;
  59. right: 0;
  60. left: 0;
  61. bottom: 0;
  62. .video{
  63. width: 100vw;
  64. height: 100vh;
  65. }
  66. }
  67. }
  68. </style>