1

I am looking to clone this tag the number of times there is a day in the month:

<td class="day noclass" v-on:click="workedDay" :class="{ active: isActive }"></td>

I tried with that:

let tdCells;
  for ( let j = 1; j <= this.nbDaysInMonth; j++)
  {
    tdCells = document.createElement("td");
    tdCells.setAttribute("class", "dayOfMonth");
    tdCells.setAttribute(":class", "{ active: isActive }");
    tdCells.setAttribute("v-on:click", "workedDay");
    document.getElementsByClassName('cells')[0].appendChild(tdCells);
  }

but it creates html attribute but not usable with VueJs

2
  • What you're looking for is v-for. I suggest you read the basic vuejs introduction vuejs.org/v2/guide. Commented Apr 11, 2018 at 7:47
  • This is not how VueJS works.You shouldn't touch DOM directly, everything should go over the model aka data object. Commented Apr 11, 2018 at 7:53

1 Answer 1

2

You can use v-for to loop through object

<tr v-for="day in nbDaysInMonth">
    <td class="day noclass" v-on:click="workedDay" :class="{ active: isActive }"></td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.