Welcome to OGeek Q&A 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 Reply

0 votes
by (71.8m points)

@click.stop.native


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...