vuejs / vue-web-component-wrapper

(Vue 2 only) Wrap a Vue component as a web component / custom element.
1.05k stars 100 forks source link

Event not emitting in Web Component Slot #98

Open kat3su opened 3 years ago

kat3su commented 3 years ago

Simple example as below. When trying to catch an event in web component slot, it's not working. Using browser onClick works fine.

web-container.vue - web component

<template> 
  <div class="wrapper">
    <slot></slot>
  </div>
</template>

app.vue - vue application

<template>
  <div>
    <web-container>
      <button @click="doSomething">Hello</button>
    </web-container>
  </div>
</template>
<script>
export default {
  methods: {
    doSomething() {
      console.log("This is not working"); // Not being console.log
    }
  }
}
</script>
zengguirong commented 3 years ago

The wrapper change the real dom to VNodes(toVNodes method) in connectedCallback. But there is no way to get the event listeners on a html element using javascript. So the wrapper lose all event listeners after the conversion. It's a serious problem.

Hobart2967 commented 3 years ago

Also, property updates do not seem to work then

kalun1988 commented 1 year ago

Same problem faced. Any workaround solution?

JamesSky commented 1 year ago

So hard