Skip to content

feat(runtime-core): support templateRef added event handler #2184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

IndexXuan
Copy link

@IndexXuan IndexXuan commented Sep 21, 2020

Support:

<template>
  <div class="container">
    <el-button ref="buttonRef">click me<el-button>
  </div>
<template>

<script>
import { ref } from 'vue'

export default {
  setup() {
    const buttonRef = ref()
    onMounted(() => {
      buttonRef.value.onClick = () => alert(`element-ui component emitted click')
      // in 2.0 we can use $on
      // buttonRef.value.$on('click', xxx)
      // even custom-event
      // buttonRef.value.onCustomEvent = () => alert('handle component emitted custom event')
    })
    return { buttonRef }
  }
}
</script>

@IndexXuan
Copy link
Author

@IndexXuan
Copy link
Author

@posva please review it, we need it a lot for our code design. Thank you

@yyx990803
Copy link
Member

This type of direct manipulation of a child ref is discouraged. I also don't see why you can't just pass the click handler via the template.

@yyx990803 yyx990803 closed this Oct 13, 2020
@IndexXuan
Copy link
Author

@yyx990803 @posva
our Lowcode tools uses templateRef to bind Model and UI, we don't use template@click directly.
also, rxjs use fromEvent https://github.com/antfu/vueuse/tree/master/packages/rxjs, while these only support native button element, prevent all vue UI librarys. sad.

We need these to implement useEventListener and useFromEvent, Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants