使用 VueJs 复制一个 html 标签



我希望克隆这个标签的月份一天的次数:

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

我试过了:

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);
  }

但它创建了 html 属性,但不能与 VueJs 一起使用

您可以使用 v-for 遍历对象

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

最新更新