A
A
Abdul Amenov2020-01-01 09:45:44
Vue.js
Abdul Amenov, 2020-01-01 09:45:44

How to create elements dynamically in Vue.js?

An array is passed to the component:

flyingButtons: [
  {
    tag: "a",
    tel: true,
    email: false,
    link: "87776665544",
    class: "btn-primary",
    title: "Позвонить"
  },{
    tag: "button",
    tel: false,
    email: false,
    link: "",
    class: "btn-success",
    title: "Оставить заявку"
  }
]

It is necessary to create elements specified by the "tag" key. We know how to pass input parameters, the question is how to create an element dynamically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-01-01
@amenov

is :

<component
  v-for="n in flyingButtons"
  :is="n.tag"
  :class="n.class"
>
  {{ n.title }}
</component>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question