A
A
Anna Shatkovskaya2018-09-26 06:07:18
Vue.js
Anna Shatkovskaya, 2018-09-26 06:07:18

How to use v-bind vue.js on multiple elements?

Hello! Started learning Vue.js and can't figure out how to assign arguments to multiple blocks?
There is this code in HTML:

<div class='useMas' v-bind:class="[activeClass, errorClass]"></div>
<div class='useMas' v-bind:class="[isActive ? activeClass : '', errorClass]"></div>
<div class='useMas' v-bind:class="[{ active: isActive }, errorClass]"></div>

JS:
new Vue({
el:'.useMas',
data: {
  activeClass: 'active',
  errorClass: 'text-danger'
}
})

It works only for one block - the first one, ignores all the rest. Can you please tell me how to make it work for other blocks too?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-26
@Miki8887

Can you please tell me how to make it work for other blocks too?

Specify the parent element of these blocks in el.
I also don't see that you have the isActive property defined. Why is it used in the template, but not in data?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question