当前位置:   article > 正文

The element or ID supplied is not valid. (videojs) elementui

the element or id supplied is not valid. (videojs)

项目问题记录 elementui ,videojs

项目用到elementui ,videojs,为了hls格式的视频流在弹框关闭后停止刷新,使用了dispose()注销player
再次打开弹窗报错

The element or ID supplied is not valid. (videojs)
  • 1

后发现因el-dialog懒加载,videojs找不到需要初始化的playerID,因为需要防止hls视频流一直刷新必须要删除dom

完整解决方案如下(无关代码有省略):

dialog捕捉关闭事件,开启事件,开启后事件

  <el-dialog title="视频播放" :visible.sync="videoVisible"  customClass="customClass"     @close="closevideo" @open="open" @opened="openvideo"> 
     <div style="position:relative;" v-html="videohtml"> 
     </div> 
     </div>
  • 1
  • 2
  • 3
  • 4

相关methods:

 closevideo() {
      if (this.player) {
        this.player.dispose(); // 该方法会重置videojs的内部状态并移除dom
        this.videohtml = '';
      }
      this.videoVisible = false;
    },
    handlePlay() {  
      this.videoVisible = true; 
    },
    open(){
       this.videohtml = '<video id="currentPlayer" class="video-js vjs-big-play-centered  vjs-default-skin " style="width:700px;height:393.75px" muted></video>';
    },
    openvideo() { 
       setTimeout(() => {
         this.$nextTick(() => { 
          this.player = Videojs("currentPlayer", this.options);
         });
    },300)
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

over

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/675428
推荐阅读
相关标签
  

闽ICP备14008679号