如何正确地将参数传递给yew函数组件中的onclick事件处理程序?
我所拥有的:
#[function_component(Calculator)]
pub fn calulator() -> Html {
let navigator = use_navigator().unwrap();
let handle_formula_click = Callback::from(move |_| {
navigator.push(&AppRoute::Formula { id })
});
html! {
<div>
...
<button onclick={handle_formula_click}>
...
</button>
...
</div>
}
}
我想把一个字符串传递给handle_formula_click回调
我想要什么:
#[function_component(Calculator)]
pub fn calulator() -> Html {
let navigator = use_navigator().unwrap();
let handle_formula_click = Callback::from(move |id: String| {
navigator.push(&AppRoute::Formula { id })
});
html! {
<div>
...
<button onclick={handle_formula_click("fixed1"}>
...
</button>
...
</div>
}
}
您可以执行以下操作:
<button onclick={ move |_|{ handle_formula_click.emit("fixed1");}}>