#[component(Backend = DomBackend)]
struct MyChild {
template: template! {
<div> "This line is in the child component." </div>
},
pub my_event: Event<String>,
}
impl Component for MyChild {
fn new() -> Self {
Self {
template: Default::default(),
my_event: Default::default(),
}
}
fn created(&self) {
let mut data = "my event data".to_string();
self.my_event.trigger(&mut data);
}
}
#[component(Backend = DomBackend)]
struct MyWebsite {
template: template! {
<MyChild my_event=@handle_my_event() />
}
}
impl Component for MyWebsite {
fn new() -> Self {
Self {
template: Default::default(),
}
}
}
impl MyWebsite {
fn handle_my_event(this: ComponentEvent<Self, String>) {
log::debug!("{}", this.detail());
}
}