DEV Community

构建组件 (opens in new tab)

Discussed on DEV

项目代码: 组件简介 组件是任何 euv 应用的构建块。它们让你将 UI 拆分为独立的、可复用的片段,每个片段都有自己的逻辑和展示。在 euv 中,组件是接受一个 VirtualNode(携带 props 和子节点)并返回一个 VirtualNode(描述渲染输出)的函数。 定义组件 要在 euv 中定义组件,你需要两个东西: 一个 Props 结构体,定义组件接受的数据 一个用 #[component] 属性装饰的组件函数 Props 结构体 Props 结构体定义了组件接收的数据的形状。它必须派生 Clone 和 Default: #[derive(Clone, Default)] struct MyCardProps { title: &'static str, } Props 可以是各种类型,包括: &'static str — 静态字符串切片,适合固定文本 String — 拥有的字符串,适合动态文本 bool — 布尔值,用于标志位 Signal — 响应式布尔信号 i32、f64 — 数值类型 Option > — 可选...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help