Dioxus-6.rs
· 674 B · Rust
原始文件
fn Counters() -> impl IntoView {
let counters = RwSignal::new(vec![0; 10]);
view! {
<button on:click=move |_| counters.update(|n| n.push(n.len()))>"Add Counter"</button>
<For
each=move || 0..counters.with(Vec::len)
key=|idx| *idx
let:idx
>
<li>
<button on:click=move |_| counters.update(|n| n[idx] += 1)>
{Memo::new(move |_| counters.with(|n| n[idx]))}
</button>
<button on:click=move |_| counters.update(|n| { n.remove(idx); })>
"Remove"
</button>
</li>
</For>
}
}
1 | fn Counters() -> impl IntoView { |
2 | let counters = RwSignal::new(vec![0; 10]); |
3 | |
4 | view! { |
5 | <button on:click=move |_| counters.update(|n| n.push(n.len()))>"Add Counter"</button> |
6 | <For |
7 | each=move || 0..counters.with(Vec::len) |
8 | key=|idx| *idx |
9 | let:idx |
10 | > |
11 | <li> |
12 | <button on:click=move |_| counters.update(|n| n[idx] += 1)> |
13 | {Memo::new(move |_| counters.with(|n| n[idx]))} |
14 | </button> |
15 | <button on:click=move |_| counters.update(|n| { n.remove(idx); })> |
16 | "Remove" |
17 | </button> |
18 | </li> |
19 | </For> |
20 | } |
21 | } |