vue router-link 添加在定义事件

在vue学习中遇到给router-link 标签添加事件@click 、@mouseover等无效的情况

我想要做的是v-for遍历出来的选项卡,

鼠标移上去出现删除标签,移除标签消失的效果

原代码:

<router-link  v-for="(item, index) in pageMenuList" :to="{ path: item.listLink }" @mouseover="overTag(index)" @mouseout="outTag(index)">{{item.listTitle}}
<i class="contain_tab_close" v-show="selected==index"></i>
</router-link>

后在发现参考  

https://segmentfault.com/q/1010000007896386

http://www.jianshu.com/p/0a8a89687bb6

https://www.cnblogs.com/xianhuiwang/p/6726688.html

根据Vue2.0官方文档关于父子组件通讯的原则,父组件通过prop传递数据给子组件,子组件触发事件给父组件。但父组件想在子组件上监听自己的click的话,需要加上native修饰符。

所以如果在想要在router-link上添加事件的话需要@click.native这样写

所以如果要事件有效的话,改成如下:

<router-link  v-for="(item, index) in pageMenuList" :to="{ path: item.listLink }" @mouseover.native="overTag(index)" @mouseout.native="outTag(index)">{{item.listTitle}}
<i class="contain_tab_close" v-show="selected==index"></i>
</router-link>
posted @ 2018-03-29 10:30  进军码农  阅读(258)  评论(0编辑  收藏  举报