el-tree与el-popover配合使用避免事件冒泡

复制代码
  <el-tree ref="sceneTreeRef" :filter-node-method="filterNode" class="scene-layer-tree" show-checkbox
            node-key="nodeKey" :allow-drag="allowDragHandler" :allow-drop="allowDropHandler" @node-drop="handleDrop"
            :data="TreeData.list" draggable default-expand-all @check="check">
            <template #default="{ data }">
                <span :title="data.title" class="tree-item-title">
                    <i class="fal fa-folder-open" style="color: #f2cc7b; margin: 5px" v-if="data.type == 'group'"></i>
                    <!-- 可以选择用一个< span >将整个< el-popover >包起来,给span加 一个 @click.stop,即可阻止冒泡 -->
                    <span @click.stop>
                        <el-popover placement="top" :width="200" trigger="click" class="propovers">
                            <template #reference>
                                <i class="fal fa-cog icon-setting"></i>
                            </template>
                            <template #default>
                                <div class="edit-item" v-if="data.type != 'root'" @click=editLayer(data)>
                                    <i class="fal fa-edit"></i>
                                    <span>{{ $t("x_edit") }}</span>
                                </div>
                                <div class="edit-item" v-if="data.type == 'group' || data.type == 'root'"
                                    @click="addNewLayer(data)">
                                    <i class="fal fa-layer-plus"></i>
                                    <span>{{ $t("x_add_a_new_layer") }}</span>
                                </div>
                                <div class="edit-item" v-if="data.type == 'group' || data.type == 'root'"
                                    @click="addFolder(data)">
                                    <i class="fal fa-folder-plus"></i>
                                    <span>{{ $t("x_add_folders") }}</span>
                                </div>
                                <div class="edit-item" v-if="data.type != 'root'" @click="deleteLayerFromTree(data)">
                                    <i class="fal fa-trash-alt"></i>
                                    <span>{{ $t("x_delete") }}</span>
                                </div>
                            </template>
                        </el-popover>
                    </span>
                    {{ data.title }}
                </span>
            </template>
        </el-tree>

解决方法: 可以选择用一个< span >将整个< el-popover >包起来,给span加 一个 @click.stop,即可阻止冒泡

相关推荐
橙子家15 小时前
浏览器缓存之【身份与会话管理】:Cookies 和 Private state tokens
前端
To_OC16 小时前
LC 49 字母异位词分组:想到哈希表很简单,选对 key 才是精髓
javascript·算法·leetcode
最新资讯动态16 小时前
HDC 2026 | 对话鲸鸿动能:存量时代,品牌如何夺回营销“主动权”?
前端
最新资讯动态16 小时前
游戏出海,从产品走向体系
前端
最新资讯动态16 小时前
20人团队跑出百万DAU、大厂也来抢量:谁在鸿蒙生态跑出加速度
前端
最新资讯动态16 小时前
千万开发者背后,鸿蒙商业化的B面
前端
爱勇宝18 小时前
AI 时代:智商决定起点,情商决定走多远
前端·ai编程
kyriewen18 小时前
用了半年 Claude Code 后,我尝试关掉它写了一周代码——结果比想象中严重
前端·javascript·ai编程
IT_陈寒19 小时前
Vite的静态资源打包让我熬夜到三点,这坑千万别跳
前端·人工智能·后端
山河木马20 小时前
矩阵专题0-webGL中的矩阵
javascript·webgl·计算机图形学