小程序富文本解析了多个video,如何做到只能一个播放 其它video暂停播放 没法给video加ref和点击事件 因为是富文本编辑器

<div v-html="info.brief" class="content" ref="editor" @click="judgeImg($event)"></div>

<script>
export default {
  mounted() {
    const observer = new MutationObserver(this.addVideoListeners);
    const editorElement = this.$refs.editor; // 假设富文本编辑器有一个ref="editor"
    observer.observe(editorElement, { childList: true, subtree: true });
  },
  beforeDestroy() {
    // 清除MutationObserver
    const observer = new MutationObserver(this.addVideoListeners);
    const editorElement = this.$refs.editor;
    observer.disconnect();
  },
  methods: {
    addVideoListeners(mutations) {
      mutations.forEach(mutation => {
        mutation.addedNodes.forEach(node => {
          if (node.tagName.toLowerCase() === 'video') {
            // 为新添加的video元素添加事件监听器
            node.addEventListener('play', this.pauseOtherVideos);
          }
        });
      });
    },
    pauseOtherVideos(event) {
      const videos = this.$el.querySelectorAll('video');
      videos.forEach(video => {
        if (video !== event.target) {
          video.pause();
        }
      });
    }
  }
};
</script>

主要是富文本编辑器里的视频 所以比较难折腾

最近更新

  1. TCP协议是安全的吗?

    2024-04-22 07:36:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-22 07:36:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-22 07:36:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-22 07:36:04       18 阅读

热门阅读

  1. 实现 Android 设备屏幕录制的批处理脚本

    2024-04-22 07:36:04       11 阅读
  2. centos常见的命令

    2024-04-22 07:36:04       16 阅读
  3. Spark在大数据集群下的部署

    2024-04-22 07:36:04       14 阅读
  4. Golang函数重试机制实现

    2024-04-22 07:36:04       13 阅读
  5. Deepin中安装Golang1.22

    2024-04-22 07:36:04       11 阅读
  6. 使用idea如何打开python项目

    2024-04-22 07:36:04       14 阅读
  7. 【LeetCode热题100】【子串】最小覆盖子串

    2024-04-22 07:36:04       11 阅读
  8. FFMPEG C++封装(三)

    2024-04-22 07:36:04       13 阅读
  9. Delete the specified node in the linked list with dummy header

    2024-04-22 07:36:04       11 阅读
  10. mac tcp实现客户端与服务端进行图像传输及处理

    2024-04-22 07:36:04       12 阅读