add eventHandler after component mounted
What problem does this feature solve?
I am writing VCA called useEventListener,which can be used to addEventListener with native HTML element and $on with Vue Component(2.0 @vue/composition-api)。while in Vue 3.0, there are no $on any more and cannot add new eventHandler after component mounted(e.g. with component ref)
What does the proposed API look like?
<el-button @click="handleClick">click</el-button>,then we can use handleClick
but with
<el-button ref="buttonRef">click me</el-button>
useEventListener('click', evt => alert(1), false, buttonRef) // cannot get buttonRef.$on or set buttonRef.onClick(onXXX) in 3.0
readonly proxy can set onXXX instead of reject with warning message
See https://v3.vuejs.org/guide/migration/events-api.html#overview
Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server or StackOverflow.
@posva bro, I know use other event emitter instead of new Vue. It is feature, not question
buttonRef.$props.onClick = evt => alert(1) not work because of code https://github.com/vuejs/vue-next/blob/f316a332b055d3f448dc735365551d89041f1098/packages/reactivity/src/baseHandlers.ts#L200
It means if we want add eventHandler, the only way is @click in template, we cannot do the same thing when we got buttonRef in setup. any way ? But in 2.0 is OK
The components no longer implement that API: https://v3.vuejs.org/guide/migration/events-api.html#overview it went through an RFC https://github.com/vuejs/rfcs/pull/118
https://github.com/vuejs/vue-next/pull/2184 @posva Hi Bro, please review mine