vue富文本编辑器里有多个video某一个video播放的时候 其它video就暂停 没法给video加ref和点击事件 因为是富文本编辑器

javascript 复制代码
<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 小时前
策略模式和状态模式到底啥区别?拿审批流表单说个明白
javascript
vim怎么退出1 小时前
谷歌性能优化知识点总结
前端
专业抄代码选手1 小时前
在react中,TSX是如何转变成JS的
前端·javascript
葡萄城技术团队1 小时前
【实践篇】从零到一:手把手教你搭建一套企业级 SpreadJS 协同设计器
前端
进击的尘埃2 小时前
SOLID 原则在 React 组件库里怎么落地:五个重构案例
javascript
忆江南2 小时前
# iOS Block 深度解析
前端
米丘2 小时前
vue-router v5.x 路由模式关于 createWebHistory、 createWebHashHistory的实现
前端
本末倒置1832 小时前
Bun 内置模块全解析:告别第三方依赖,提升开发效率
前端·javascript·node.js
踩着两条虫2 小时前
AI 驱动的 Vue3 应用开发平台 深入探究(二):核心概念之DSL模式与数据模型
前端·vue.js·ai编程
进击的尘埃2 小时前
中介者模式:把面板之间的蜘蛛网拆干净
javascript