Vue自定义事件 事件解绑与销毁


组件自定义事件 事件解绑 组件销毁

组件名标签上绑定事件,相当于给vc绑定自定义事件,要用$emit才能触发. 如果一定要使用,写成click.native
组件内一般元素上绑定时间,事件的回调可以写在methods里面

子传父

  • v-on|once + $emit
  • mounted + ref + $emit

案例

App.vue





CustomChild.vue






组件销毁与自定义事件解绑


解绑事件

this.$off('e')
this.$off(['e','e1'])
this.$off() // 所有自定义事件

销毁组件实例

this.$destory 组件销毁后,自定义事件全部失效
vue