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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *