Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

vue-element 阻止事件冒泡没效果,怎么解决?

代码:

<el-menu>
<template v-for="item in menuList">
                        <el-submenu :index="item.index" @click.native="ClickSubMenu"   >
                          <template slot="title"  >
                            <i class="el-icon-location"></i>
                            <span>{{item.title}}</span>
                          </template>
                          <template v-for="menu in item.child">
                            <el-menu-item @click.stop="ChildMenuClick(item,menu,$event)" >{{menu.title}}</el-menu-item>
                          </template>
                           
                        </el-submenu>
                      
                    </el-menu>
ChildMenuClick(item,child,event){
              alert("456");
                
            },

            ClickSubMenu(row){
              alert("123");
            }

我用navmenu菜单,我要为submenu设置点击事件,以及子菜单点击事件,点击子菜单,后会触发子菜单事件ChildMenuClick,然后会触发subMenu事件ClickSubMenu。

查了一下是事件冒泡,我使用了@click.stop代码,效果却是点击子菜单不会触发ChildMenuClick事件了,只会触发subMenu事件,这个怎么解决啊?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

@click.stop.native


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...