mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* change suffixes from md to mdx fix broken links for English locale tree shake and update docusaurus add docusaurus ideal image plugin use svg and themed image delete unused static asset * move localized landing page * change GitLocalize project page * nit pick * remove ignore to have the block checked
26 lines
742 B
Plaintext
26 lines
742 B
Plaintext
---
|
|
title: Refs
|
|
description: Out-of-band DOM access
|
|
---
|
|
|
|
`ref`は、任意のHTML要素やコンポーネントの内部で、割り当てられているDOM`Element`を取得するために使用することができます。
|
|
これは、`view` ライフサイクルメソッドの外でDOMに変更を加えるために使用できます。
|
|
|
|
これは、キャンバスの要素を取得したり、ページの異なるセクションにスクロールしたりするのに便利です。
|
|
|
|
構文は以下の通りです:
|
|
|
|
```rust
|
|
// In create
|
|
self.node_ref = NodeRef::default();
|
|
|
|
// In view
|
|
html! {
|
|
<div ref={self.node_ref.clone()}></div>
|
|
}
|
|
|
|
// In update
|
|
let has_attributes = self.node_ref.try_into::<Element>().has_attributes();
|
|
```
|
|
|