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 小时前
JavaScript vs Python 用于 Web Scraping(2025):终极对比指南
前端·chrome·chrome devtools·指纹浏览器·浏览器开发·超级浏览器
风逸hhh5 小时前
python打卡day29@浙大疏锦行
开发语言·前端·python
LuckyLay5 小时前
Vue百日学习计划Day33-35天详细计划-Gemini版
前端·vue.js·学习
ᖰ・◡・ᖳ5 小时前
JavaScript:PC端特效--缓动动画
开发语言·前端·javascript·css·学习·html5
会飞的鱼先生6 小时前
vue2、vue3项目打包生成txt文件-自动记录打包日期:git版本、当前分支、提交人姓名、提交日期、提交描述等信息 和 前端项目的版本号json文件
前端·vue.js·git·json
!win !6 小时前
uni-app项目从0-1基础架构搭建全流程
前端·uni-app
c_zyer7 小时前
使用 nvm 管理 Node.js 和 npm 版本
前端·npm·node.js
布Coder7 小时前
前端 vue + element-ui 框架从 0 - 1 搭建
前端·javascript·vue.js
i_am_a_div_日积月累_7 小时前
Element Plus 取消el-form-item点击触发组件,改为原生表单控件
前端·vue.js·elementui
集成显卡7 小时前
网页 H5 微应用接入钉钉自动登录
前端·后端·钉钉