-
Notifications
You must be signed in to change notification settings - Fork 19
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
cutom events #27
Comments
Hey @echb! |
The 3rd block at https://polight.github.io/lego-demo/ will show you a demo of a webcomponent updated from a CustomEvent, that's the most simplistic version. |
The component code <template>
<div class="container" @click="test">
<div class="container">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur ut quos error totam reprehenderit fuga
aperiam, explicabo quisquam, architecto at cumque assumenda illum corrupti natus facilis quasi, doloribus
laborum
odio.</p>
</div>
</template>
<script>
export default class extends Lego {
connected() {
}
init() {
this.state = {
}
}
test() {
const MessageEvent = new CustomEvent("message", {
detail: { from: "Manz", message: "Hello!" },
bubbles: true,
composed: true
});
this.dispatchEvent(MessageEvent);
}
}
</script>
<style>
.container {
display: inline-flex;
background-color: #9f1717;
color: antiquewhite;
padding: 2px 5px 2px 5px;
border-radius: 10px;
}
::slotted(*) {
display: inline-block;
/* background-color: green; */
border: none;
margin: 0;
padding: 0;
}
</style> This is script calling outside component const prop = document.querySelector('lego-prop')
prop.addEventListener('message', (e) => {
console.log(e);
}) The problem comes whe nest components <template>
<div class="container">
<p>component with nested one</p>
<div class="container">
<lego-prop @message="test"></lego-prop>
</div>
</template>
<script>
export default class extends Lego {
connected() {
console.log('asd');
}
init() {
this.state = {
}
}
test(e) {
console.log(e);
}
}
</script> |
Hey @echb! I'm pretty confident we should work this out :) |
i've tried use custom events and i failed forthright, someone has used lego with custom events?
The text was updated successfully, but these errors were encountered: