Knowledgebase

Vue Templates and Directives Print

  • frontenddevelopment, frontend, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Describing the interface.

WHAT A TEMPLATE IS

Markup with additional syntax for binding data and behaviour.

WHAT THE COMMON DIRECTIVES DO

Bind an attribute to a value Render conditionally Render a list Attach an event handler Bind an input two ways

WHAT TWO-WAY BINDING PROVIDES

An input and a value kept synchronised, without writing the handler.

WHAT TO BE CAREFUL WITH

Conditional rendering and list rendering on the same element Complex expressions in templates

WHAT TO DO ABOUT THAT SECOND POINT

Move them into computed values.

WHY

Templates should describe structure, not contain logic.

WHAT KEYS ARE FOR IN LISTS

Identifying items between renders, as in any framework.

WHAT TO USE

A stable identifier, not the index where the list changes.

WHAT SLOTS PROVIDE

Passing content into a component from its parent.

WHY THAT MATTERS

It keeps components flexible without accumulating props.

WHAT TO KEEP IN TEMPLATES

Structure, simple conditions and loops.

WHAT TO KEEP OUT

Data fetching, business rules and complex computation.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot