Vue 3 Declarative Rendering
Declarative Rendering means updating the view driven by data, rather than directly manipulating the DOM.
Declarative rendering lets developers focus more on business logic, without worrying about how to update the view and DOM.
Vue 3's declarative rendering is a template-based rendering approach that lets developers describe the page structure and data binding relationships through concise template syntax, without directly manipulating the DOM.
Vue 3's declarative rendering simplifies the UI update process by using templates, directives (such as v-if, v-for, v-bind, etc.), and reactive data.
Vue's declarative rendering lets you simply declare how the UI should look; Vue automatically updates the view based on data changes, and the view responds automatically when you change the data.
Vue 3 uses template syntax (similar to HTML) to describe the UI, and expressions in the template (such as {{ message }}) are bound to the component's data model.

1. Data Binding
Data binding is the core of declarative rendering.
By binding data, Vue can automatically update the content of DOM elements, avoiding traditional manual DOM manipulation.
Interpolation Expressions
Interpolation expressions insert component data into the HTML template using double curly braces {{ }}.
Example
<
template
<
div
<
h1
{
{
message
}
}
h1
div
template
<
script
export
default
{
data
(
)
{
return
{
message:
'Hello, Vue 3!'
}
;
}
}
;
script
In the example above, the double curly braces {{ message }} are rendered as Hello, Vue 3!, and when the value of message changes, the view updates automatically.
The content inside the double curly braces is not limited to identifiers or paths—we can use any valid JavaScript expression.
{{ message.split('').reverse().join('') }}
Attribute Binding
With the v-bind directive, you can bind HTML attributes to component data, so that the DOM element's attributes (such as href, class, src) update dynamically based on the component's state.
Example
In the example above, v-bind:href binds the url data to the tag's href attribute, and when url changes, href updates automatically.
Conditional Rendering
Vue implements conditional rendering through the v-if, v-else-if, and v-else directives, deciding whether to render a DOM element based on a data condition.
Example
This text is visible
Toggle visibility
In the example above, when isVisible is true, the
tag is rendered; when the button is clicked, isVisible is toggled, and the
tag's visibility changes automatically as well.
List Rendering
You can render a list using the v-for directive.
Vue renders the corresponding DOM element for each item in the array, and automatically updates the view when the array data changes.
Example
-
{{ item.name }}
In the example above, v-for renders a list based on the items array. Each list item has a key to help Vue track each item, thereby improving rendering efficiency.
Two-Way Data Binding
Vue provides the v-model directive to achieve two-way binding between form elements (such as ) and component data, so that the form element's value stays in sync with the data model: data updates automatically on user input, and the view updates automatically when the data changes.
Example
You entered: {{ message }}
In the example above, v-model keeps the input element's value in sync with the message data. When the user types text in the input box, message updates automatically,
and the content inside the tag changes automatically as well.
Event Handling
Vue provides the v-on directive to listen for DOM events and execute methods when events are triggered, allowing you to declaratively handle events such as user input and clicks.
Example
Click count: {{ count }}
In the example above, v-on:click listens for the button's click event and calls the increment method on each click to increase the value of count, which is automatically reflected in the view.
Computed Properties
Computed properties are a declarative way provided by Vue to compute values.
Computed properties are based on reactive data and are only recomputed when the dependent data changes.
Example
Original amount: {{ amount }}
Amount after tax: {{ computedAmount }}
computedAmount is a computed property that derives the after-tax amount based on amount. When amount changes, computedAmount updates automatically without manually triggering a view update.