$attrs、$listeners、$props的使用

$attrs、$listeners、$props的使用

这三个 ,在创建组件多层嵌套时,特别有用

  1. $attrs包含了父作用域中不作为 prop 被识别 (且获取) 的 attribute 绑定 (class 和 style 除外)。
  2. $props当前组件接收到的 props 对象。

  1. $listeners 包含了父作用域中的 (不含 .native 修饰器的) v-on 事件监听器。它可以通过 v-on="$listeners" 传入内部组件。避免了普通的那种方式,一层层的传到顶级组件,这样太繁琐了

posted @ 2020-09-17 03:18  玖舞二柒  阅读(231)  评论(0)    收藏  举报