I have an array of items like 'Item 1', 'Item 2' up to 'Item 25'. I want the HTML after rendering look like this:
<div class="row">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
<div>Item 5</div>
</div>
<div class="row">
<div>Item 6</div>
<div>Item 7</div>
<div>Item 8</div>
<div>Item 9</div>
<div>Item 10</div>
</div>
What is the proper way to express this in vue.js?
<div class="row">
<span v-for="(item, index) in items">
// do something like this in vue.js style:
// if (item % 5 == 0) print "</div><div class='row'>"
<app-field >{{ item }}</app-field>
</span>
</div>
In addition to the example above which I think is fine, I would define the calculations as computed properties and methods for more readable code. See the JSFiddle:
Or you can do the same using
lodash _.chunk()
, which personally I find more readable.Template:
Then
Personally I import lodash globally as I use it so often, in main.js:
Remember to '
npm install --save lodash
'You can try this:
See a working example: