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

Bindings, Actions & Transitions

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

  • Bindings (bind:) สร้าง link สองทางระหว่าง state กับ DOM property — input update state และ state update input
  • Actions (use:) run โค้ด setup แบบ imperative บน element ตอน mount — escape hatch สำหรับ library ที่ไม่ใช่ Svelte, focus, tooltip และ click-outside
  • Transitions & animations (transition:, animate:) animate element แบบ declarative ตอนเข้า ออก และเรียงใหม่
บทเรียนสิ่งที่จะได้เรียน
Bindingsbind:value, bind:this, bind:group และ component binding
Actionsuse: directive และ action lifecycle
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 ทำอะไร?