Vue v-bind Directive

Vue v-bind Directive
It allows attribute values to change automatically when data changes.
What is Vue v-bind Directive?
v-bind connects an HTML attribute with a Vue data property.
Without v-bind, attributes are static
With v-bind, attributes become dynamic
Basic Syntax
Shorthand (Most Common)
Example 1: Binding an Image Source
When imageUrl changes, the image updates automatically.
Example 2: Binding a Link (href)
Example 3: Binding class
You can dynamically apply CSS classes.
Using Object Syntax
Using Array Syntax
Example 4: Binding style
Inline styles can also be dynamic.
Example 5: Binding Boolean Attributes
Button becomes disabled when isDisabled is true.
v-bind with Components
This passes dynamic props to components.
Key Points to Remember
v-bindmakes attributes reactiveUse shorthand
:for cleaner codeWorks with:
srchrefclassstyledisabled,checked, etc.
Essential for dynamic UI
Summary Table
| Usage | Example |
|---|---|
| Bind attribute | :src="imageUrl" |
| Bind class | :class="{ active: isActive }" |
| Bind style | :style="{ color: 'red' }" |
| Boolean attribute | :disabled="true" |
| Component props | :title="pageTitle" |
Conclusion
The v-bind directive is a core concept in Vue.
Without it, Vue apps cannot be truly dynamic.
