v0.6.22

Lifecycle Hooks

Last updated


This page covers when each hook in the when option fires, what it receives, and how to cancel a render.

Syntax


  1. <div id="app">
  2. <p>{{ count }}</p>
  3. <button @click="add">+1</button>
  4. </div>
  5. <script>
  6. const app = new QUI({
  7. id: "app",
  8. data: { count: 0 },
  9. event: {
  10. add: () => app.data.count++,
  11. },
  12. when: {
  13. beforeRender: () => {},
  14. rendered: (sec) => console.log("rendered in", sec),
  15. beforeUpdate: () => app.data.count < 10,
  16. updated: (sec) => console.log("updated in", sec),
  17. },
  18. });
  19. </script>
Live preview · @pardnchiu/quickui@0.6.22

Hook List


HookFiresArgumentReturning false
beforeRenderBefore the initial renderNoneCancels the initial render; the raw template stays on screen
renderedAfter the initial render reaches the DOMDuration in secondsNo effect
beforeUpdateAfter a data change and the 300 ms debounceNoneCancels this update
updatedAfter the update reaches the DOMDuration in secondsNo effect
beforeDestroyNever fires in the current versionNoneNone
destroyedNever fires in the current versionNoneNone

beforeDestroy and destroyed are accepted, but QUI has no public destroy method, so they are never called.

Rules


RuleDescription
CancellingOnly a synchronous false cancels; an async function returns a Promise and cannot cancel
Update debounceMultiple writes within 300 ms trigger beforeUpdate / updated once
Reading dataapp.data is ready from rendered onward, see Reactive Data

Legacy Forms


Hooks placed in a lifecycle object, at the top level of the options, or named in snake_case such as before_render, before_update and before_destroy still work but are planned for removal in 1.0.0; see Deprecations.
中文