Configs2026年4月12日·1 分钟阅读

Leptos — Build Fast Web Applications with Rust

Leptos is a full-stack Rust web framework with fine-grained reactivity. Compiles to WebAssembly for the client and runs server functions natively. Signals-based reactivity (like SolidJS), server-side rendering, and hydration.

AI
AI Open Source · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

cargo install cargo-leptos
cargo leptos new my_app
cd my_app
cargo leptos watch                          # Dev server with SSR + WASM
cargo leptos build --release                # Production build
use leptos::prelude::*;

#[component]
fn App() -> impl IntoView {
    let (count, set_count) = signal(0);

    view! {
        <h1>"Count: " {count}</h1>
        <button on:click=move |_| set_count.update(|n| *n += 1)>
            "Click me"
        </button>
    }
}

fn main() {
    mount_to_body(App);
}
介绍

Leptos is a full-stack Rust web framework with fine-grained reactivity, inspired by SolidJS. Components compile to WebAssembly for the client and run natively on the server. Server functions, streaming SSR, hydration, and Actix/Axum integration. Created by Greg Johnston.

What Leptos Does

  • Fine-grained reactivity — signals (like SolidJS, not VDOM)
  • SSR — server-side rendering with streaming
  • Hydration — pick up server-rendered HTML on client
  • Server functions#[server] functions called from client
  • Routing — file-based or declarative
  • Suspense — async data loading boundaries
  • Islands — partial hydration for minimal WASM
  • Actix or Axum — server integration

Comparison

Framework Reactivity SSR WASM
Leptos Signals Streaming Yes
Dioxus Signals Yes Yes
Yew VDOM Yes Yes
SolidJS Signals Yes No (JS)

常见问题 FAQ

Q: 为什么选 signals 而非 VDOM? A: Signals 只更新变化的 DOM 节点(O(1)),VDOM 需要 diff 整个树(O(n))。性能更好、WASM bundle 更小。

Q: 和 SolidJS 类似? A: 非常类似。Leptos 的 API 设计深受 SolidJS 启发,但全栈 Rust(类型安全 + WASM 性能)。

来源与致谢 Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产