00.stencil:03.stencilの_propと_state
差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| 00.stencil:03.stencilの_propと_state [2019/09/26] – [@prop()の解説のリンク] adash333 | 00.stencil:03.stencilの_propと_state [2019/09/26] (現在) – [@state()の解説のリンク] adash333 | ||
|---|---|---|---|
| 行 58: | 行 58: | ||
| https:// | https:// | ||
| State Decorator(公式ドキュメント) | State Decorator(公式ドキュメント) | ||
| + | |||
| + | 内容が変化する可能性のあるデータには、 | ||
| + | @state()デコレータをつけるそうです。 | ||
| + | |||
| + | Any changes to a @State() property will cause the components render function to be called again. | ||
| + | @State() propertyが変更されるたびに、コンポーネントのrender関数が呼び出される(再描画される)。 | ||
| + | |||
| + | https:// | ||
| + | |||
| + | コンポーネント | ||
| + | < | ||
| + | @State() holdings: Holding[] = []; | ||
| + | </ | ||
| + | と、holdingsに@State()をつけることで、 | ||
| + | < | ||
| + | componentDidLoad() { | ||
| + | const router = document.querySelector(" | ||
| + | |||
| + | // Refresh data every time view is entered | ||
| + | router.addEventListener(" | ||
| + | const holdings = await Holdings.getHoldings(); | ||
| + | this.holdings = [...holdings]; | ||
| + | }); | ||
| + | } | ||
| + | </ | ||
| + | により、ページのアドレスが変化するたびに、holdingsが再描画されて、表示されるものが最新のものになるようにしています。 | ||
| + | |||
| + | |||
00.stencil/03.stencilの_propと_state.1569460810.txt.gz · 最終更新: 2019/09/26 by adash333
