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>

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

相关推荐
知识分享小能手25 分钟前
Vue3 学习教程,从入门到精通,Axios 在 Vue 3 中的使用指南(37)
前端·javascript·vue.js·学习·typescript·vue·vue3
程序员码歌3 小时前
【零代码AI编程实战】AI灯塔导航-总结篇
android·前端·后端
用户21411832636024 小时前
免费玩转 AI 编程!Claude Code Router + Qwen3-Code 实战教程
前端
小小愿望5 小时前
前端无法获取响应头(如 Content-Disposition)的原因与解决方案
前端·后端
小小愿望5 小时前
项目启功需要添加SKIP_PREFLIGHT_CHECK=true该怎么办?
前端
烛阴5 小时前
精简之道:TypeScript 参数属性 (Parameter Properties) 详解
前端·javascript·typescript
海上彼尚6 小时前
使用 npm-run-all2 简化你的 npm 脚本工作流
前端·npm·node.js
开发者小天6 小时前
为什么 /deep/ 现在不推荐使用?
前端·javascript·node.js
如白驹过隙7 小时前
cloudflare缓存配置
前端·缓存
excel7 小时前
JavaScript 异步编程全解析:Promise、Async/Await 与进阶技巧
前端