karol-f / vue-custom-element

Vue Custom Element - Web Components' Custom Elements for Vue.js
https://karol-f.github.io/vue-custom-element/
MIT License
1.97k stars 187 forks source link

How can I catch event in html? #228

Closed Kosmostars7403 closed 3 years ago

Kosmostars7403 commented 3 years ago

I prepared an codesandbox example. How can I make it works? To start a testFunc! Why v-on: doesn't work?

example

Thank you!

karol-f commented 3 years ago

Because You cannot use Vue specific language (like v-on) in HTML. It's recognizable only in Vue components.

Do You have other questions?

Kosmostars7403 commented 3 years ago

Yes, which way is the best to solve my problem? Wrap into another Vue component?

Kosmostars7403 commented 3 years ago

maybe i can trigger any function from Vue-custom-component event without HTML eventListeners?

karol-f commented 3 years ago

IMHO treat vue-custom-element as mini app and put that what is shown in example inside custom element

Kosmostars7403 commented 3 years ago

My lead wants external business logic. I need to find the way( Thnx.

karol-f commented 3 years ago

maybe i can trigger any function from Vue-custom-component event without HTML eventListeners?

Yes, You have getVueInstance(), e.g.

document.querySelector('widget-vue').getVueInstance()

Feel free to ask more questions if You still need something different.