Subscribe on changes!

kebab-cased event handler as prop not called on emit

avatar
Dec 12th 2023

I don’t think this is a bug, I think :on-some-event will be processed as props, binding events in vue should use v-on or @ abbreviation

v-on:some-event
or
@some-event
avatar
Dec 12th 2023

If you use props to pass events, you should trigger the event through props in the child component.

<script setup>
defineProps(['onSomeEvent'])
</script>

<template>
  <div>
   <button @click="(e) => onSomeEvent(e)">trigger</button>
  </div>
</template>
avatar
Dec 12th 2023

@leoelz usage

avatar
Dec 12th 2023

Thanks @baiwusanyu-c and @Simon-He95, I know about the other ways to use it and the recommendations. But the possibility of using <Comp :onSomeEvent="" /> is allowed, but kebab-case is recommended as prop naming, that's why I've worked on this fix. Here is the doc: https://vuejs.org/guide/components/events.html#events-props And here is the playground with different tests I've done, where I've found the issue with kebab-case.

avatar
Dec 12th 2023

When using events starting with:, props.event needs to be used internally to trigger them, while events starting with @ use emit. The bottom layer of Vue seems to convert all camel cases into hyphen.

avatar
Dec 12th 2023

Currently when kebab-case is not used, it makes no difference wether props.event() or emit('event') is used, please check here. I think, in favor of abstraction principles, it shouldn't be necessary to know how it is internally triggered.