#yew-component #yew #component #windowing

yew-virtual-scroller

一个用于虚拟滚动/滚动窗口的 Yew 组件

1 个不稳定版本

0.1.0 2020 年 12 月 19 日

#1443 in WebAssembly

MIT/Apache

11KB
136 行代码(不含注释)

yew-virtual-scroller

Crates.io Crates.io

yew-virtual-scroller 是一个用于虚拟滚动/滚动窗口的 Yew 组件 — 只将可见内容渲染到 DOM 中。

示例

struct MyItem { value: usize }

impl From<MyItem> for yew::Html {
    fn from(item: MyItem) -> Self {
        html! {
            // Each item must be the same height.
            <div key={item.value} style="height: 32px;">
                {format!("Item: {}", item.value)}
            </div>
        }
    }
}

fn view(&self) -> yew::Html {
    // Items is wrapped with an Rc to avoid cloning large lists.
    let items = Rc::clone(&self.items);
    html! {
        <div>
            <style>{"
                /* Scroller should be constrained in some way so it can scroll */
                .scroller {
                    height: 600px;
                }
            "}</style>

            <VirtualScroller<MyItem>
                items={items}
                row_height={32.0}
                class=Classes::from("scroller")
            />
        </div>
    }
}

许可协议

根据以下任一协议授权:

由您选择。

贡献

除非您明确说明,否则任何有意提交以包含在本作品中的贡献,如 Apache-2.0 许可证中定义的,均应按照上述方式双授权,不附加任何额外条款或条件。

依赖项

~12MB
~228K SLoC