跳至主要内容
版本:0.21

子级

Children 是一种特殊的 prop 类型,它允许你接收嵌套的 Html,这些 Html 被提供为 html 子元素。

use yew::{function_component, html, Html, Properties};

#[function_component]
fn App() -> Html {
html! {
<HelloWorld>
<span>{"Hey what is up ;)"}</span>
<h1>{"THE SKY"}</h1>
</HelloWorld>
}
}

#[derive(Properties, PartialEq)]
pub struct Props {
pub children: Html, // the field name `children` is important!
}

#[function_component]
fn HelloWorld(props: &Props) -> Html {
html! {
<div class="very-stylized-container">
{ props.children.clone() } // you can forward children like this
</div>
}
}