Skip to content
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

Problems with the render function and events #215

Open
LucasBerger opened this issue Jul 1, 2020 · 3 comments
Open

Problems with the render function and events #215

LucasBerger opened this issue Jul 1, 2020 · 3 comments
Assignees

Comments

@LucasBerger
Copy link

Hey,

I am using the render(h)-function to render components and noticed that if I call a function that emits an event with the render-function-version of the v-on-directive (https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth), the event is not passed to the parent.
In the Vue devtools I can see the Event but I can't catch with the Parent-Element.

Here's a CodeSandbox-Project to make it a bit better to understand:
https://codesandbox.io/s/vue-custom-element-render-function-with-on-doesnt-work-x16zk

This is not a problem of Vue. I tried it with pure Vue and it worked. You can also try it yourself in the Project.
I hope you can help me.

Regards Lucas

@karol-f karol-f self-assigned this Jul 1, 2020
@karol-f
Copy link
Owner

karol-f commented Jul 1, 2020

@karol-f
Copy link
Owner

karol-f commented Jul 1, 2020

It's most likely due to fact that this library monkey patch $emit function in beforeCreate hook to have HTML events send to DOM element of Custom Element:

function beforeCreate() { // eslint-disable-line no-inner-declarations
  this.$emit = function emit(...args) {
    customEmit(element, ...args);
    this.__proto__ && this.__proto__.$emit.call(this, ...args); // eslint-disable-line no-proto
  };
}

It was not tested with render function and I assume that there is a problem.

Is custom event bus solution (mentioned in previous comment) enough for You?

@LucasBerger
Copy link
Author

Alright I played around with the event bus a bit and the only problem I noticed is that the events have to have unique names. Is there a simple way to check if the event is from the child component?

But still, can you invest some time into fixing this in the library? it would help a lot ^^

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

No branches or pull requests

2 participants