ข้ามไปยังเนื้อหา

Bindings, Actions & Transitions

runes ให้ reactive state; โมดูลนี้ครอบคลุม directive ที่เชื่อม state นั้นเข้ากับ DOM element จริงและกับ motion:

  • Bindings (bind:) สร้าง link สองทางระหว่าง state กับ DOM property — input update state และ state update input
  • Attachments และ actions — {@attach} (Svelte 5.29+) run โค้ด setup แบบ imperative บน element หรือ component และ run ใหม่เมื่อ input เปลี่ยน ส่วน use: action คือรูปแบบเดิมสำหรับ library ที่ยังส่ง action มาให้ — escape hatch สำหรับ library ที่ไม่ใช่ Svelte, focus, tooltip และ click-outside
  • Transitions & animations (transition:, animate:) animate element แบบ declarative ตอนเข้า ออก และเรียงใหม่
บทเรียนสิ่งที่จะได้เรียน
Bindingsbind:value, bind:this, bind:group และ component binding
Actionsattachment ({@attach}) ก่อน แล้วค่อย use: directive แบบเดิมและ fromAction
Transitions & animationstransition:/in:/out: และ animate:flip
Forms & inputscontrolled input, validation และการจัดการ submit
flowchart TB
  state["reactive state (runes)"] --> bind["bind: link สองทางกับ DOM property"]
  state --> action["use: setup แบบ imperative บน element"]
  state --> trans["transition: / animate: motion แบบ declarative"]
  bind --> dom["the DOM"]
  action --> dom
  trans --> dom
สามวิธีที่ Svelte เข้าถึง DOM
bind: directive สร้างอะไร?
use: action ใช้ทำอะไร?
transition: และ animate: directive ทำอะไร?