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

子组件

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

在父组件中绑定一个事件

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

vue组件上绑定原生事件

native的局限性

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

ps:native是针对自定义组件的

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-12-13
  • 2021-11-14
  • 2018-04-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2021-08-06
  • 2021-06-01
相关资源
相似解决方案