Vue知识点——$listeners

首先,$listeners是什么?

// Parent
<template>
  ...
  <child v-on:event-one="methodOne" v-on:event-two="methodTwo" />
  ...
</template> 

那么你在使用Child时,传入的所有v-on事件都可以在$listeners对象中找到。注意:使用.native修饰符的事件,不会体现在$listeners属性上。

// Child
created () {
  console.log(this.$listeners) // { 'event-one': f(), 'event-two': f() }
} 

 

原文链接:https://www.cnblogs.com/samve/p/11769080.html

原文地址:https://www.cnblogs.com/zhouwan/p/13535556.html