Sometimes, we want to add attribute dynamically in Vue.js.
In this article, we’ll look at how to add attribute dynamically in Vue.js.
How to add attribute dynamically in Vue.js?
To add attribute dynamically in Vue.js, we use v-bind
.
For instance, we write
<template>
<input
type="text"
:disabled="disabled"
:placeholder="placeholder"
v-model="value"
/>
</template>
to add the disabled
and placeholder
attributes dynamically.
:disabled
is short for v-bind:disabled
.
And :placeholder
is short for v-placeholder
.
We set disabled
to the value of the disabled
reactive property.
And we set placeholder
to the value of the placeholder
reactive property.
Conclusion
To add attribute dynamically in Vue.js, we use v-bind
.