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>

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

相关推荐
小小小小宇2 小时前
虚拟列表兼容老DOM操作
前端
悦悦子a啊2 小时前
Python之--基本知识
开发语言·前端·python
安全系统学习3 小时前
系统安全之大模型案例分析
前端·安全·web安全·网络安全·xss
涛哥码咖3 小时前
chrome安装AXURE插件后无效
前端·chrome·axure
OEC小胖胖3 小时前
告别 undefined is not a function:TypeScript 前端开发优势与实践指南
前端·javascript·typescript·web
行云&流水4 小时前
Vue3 Lifecycle Hooks
前端·javascript·vue.js
Sally璐璐4 小时前
零基础学HTML和CSS:网页设计入门
前端·css
老虎06274 小时前
JavaWeb(苍穹外卖)--学习笔记04(前端:HTML,CSS,JavaScript)
前端·javascript·css·笔记·学习·html
三水气象台4 小时前
用户中心Vue3网页开发(1.0版)
javascript·css·vue.js·typescript·前端框架·html·anti-design-vue
灿灿121384 小时前
CSS 文字浮雕效果:巧用 text-shadow 实现 3D 立体文字
前端·css