vue组件上绑定原生事件

将原生事件绑定在组件上 .native 修饰符:

子组件

<template>
    <div class="demo">
        <h2>我是子组件</h2>
        <h3>我是子组件中的信息</h3>
    </div>
</template>

在父组件中绑定一个事件

<test-com  @click.native="fatherHander" ></test-com>
methods:{
    fatherHander(){
    console.log('将原生事件绑定到组件');
    }
},

native的局限性

虽然这个方法使用起来非常简单,但是其存在局限性:
它只会把事件放在子组件的根标签上。

ps:native是针对自定义组件的
posted @ 2021-10-25 22:21  南风晚来晚相识  阅读(173)  评论(0编辑  收藏  举报