Categories
Vue Answers

How to add attribute dynamically in Vue.js?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.