Render Closing Tag Conditionally in Order to Emulate Calendar Behavior

Render closing tag conditionally in order to emulate calendar behavior

Usually I recommend to put the all logic in your script and only use properties and call methods in the template section, so for this case I'm gonna define a computed property called cptDays in which I loop through the days array and when I meet a normal day I push it in a week if the day is Sunday I push it and I increment the number of weeks, in the end I return the month array which I loop through it in my template.

Note

I used CSS from bootstrap to give a pretty look, you could remove it and your code will not be changed

new Vue({  el: '#app',  data: {    days: [{        "number": 1,        "isSunday": false      },      {        "number": 2,        "isSunday": false      },      {        "number": 3,        "isSunday": false      },      {        "number": 4,        "isSunday": false      },      {        "number": 5,        "isSunday": false      },      {        "number": 6,        "isSunday": false      },      {        "number": 7,        "isSunday": true      },      {        "number": 8,        "isSunday": false      },      {        "number": 9,        "isSunday": false      },      {        "number": 10,        "isSunday": false      },      {        "number": 11,        "isSunday": false      },      {        "number": 12,        "isSunday": false      },      {        "number": 13,        "isSunday": false      },      {        "number": 14,        "isSunday": true      },      {        "number": 15,        "isSunday": false      },      {        "number": 16,        "isSunday": false      },      {        "number": 17,        "isSunday": false      },      {        "number": 18,        "isSunday": false      },      {        "number": 19,        "isSunday": false      },      {        "number": 20,        "isSunday": false      },      {        "number": 21,        "isSunday": true      },      {        "number": 22,        "isSunday": false      },      {        "number": 23,        "isSunday": false      },      {        "number": 24,        "isSunday": false      },      {        "number": 25,        "isSunday": false      },      {        "number": 26,        "isSunday": false      },      {        "number": 27,        "isSunday": false      },      {        "number": 28,        "isSunday": true      },
{ "number": 29, "isSunday": false }, { "number": 30, "isSunday": false }, { "number": 31, "isSunday": false } ] }, computed: { cptDays() { let month = [], i = 0; this.days.forEach((day) => {
if (!day.isSunday) { if (month[i] == undefined) { month[i] = []; month[i].push(day) } else { month[i].push(day) }

} else { month[i].push(day) i++; } }); return month; }
}
})
<!DOCTYPE html><html>
<head> <meta name="description" content="Vue.delete"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.1/vue.min.js"></script></head>
<body> <div id="app"> <table class="table table-striped"> <thead> <tr> <th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thi</th> <th>Fri</th> <th>Sat</th> <th>Sun</th> </tr> </thead> <tbody> <tr v-for="week in cptDays"> <td v-for="day in week ">{{day.number}}</td> </tr> </tbody> </table> </div>

Vue: How to conditionally render tr in tbody

In those situations where no element would fit, you can use <template>, like:

<template v-if="team.positions != null">
<my-row v-for="position in team.positions"
:position="position"
:key="position.id">
</my-row>
</template>

Demo:

new Vue({
el: '#app',
data: {
showTwoRows: true
}
})
<script src="https://unpkg.com/vue"></script>
<div id="app">
<table>
<tr>
<td>A</td><td>B</td>
</tr>
<template v-if="showTwoRows">
<tr>
<td>1</td><td>2</td>
</tr>
<tr>
<td>3</td><td>4</td>
</tr>
</template>
<tr>
<td>C</td><td>D</td>
</tr>
</table>
<button @click="showTwoRows = !showTwoRows">Toggle two middle rows</button>
</div>

Create new row after 3 item iterations with VueJS and Skeleton CSS

You could do something like this; Use Math.ceil(items.length / 3) to calculate the number of rows needed to hold the items, loop through rows, for each row loop through items for that row, i.e. items.slice(3 * (rowIdx - 1), 3 * rowIdx).

<div class="row" v-for="rowIdx in Math.ceil(items.length / 3)">
<div class="one-third column" v-for="item in items.slice(3 * (rowIdx - 1), 3 * rowIdx)">
<custom-component :item="item"></custom-component>
</div>
</div>

SVN log file and TortoiseSVN

Tortoise displays the log by the command:

right-click/TortoiseSVN/Show Log

But I'm not sure what you mean by "this won't work since it is a remote repo and I can't define a username/password for it". SVN accepts username and password parameters:

svn log --verbose --xml --username <user> --password <password>

Vue.js print raw html and call component methods

Instead of loading html I end up saving component in JSON format. This component has a template property that stores the html string. In this way I am able to store and load component to and from database and it works without any issue.

SVN log file and TortoiseSVN

Tortoise displays the log by the command:

right-click/TortoiseSVN/Show Log

But I'm not sure what you mean by "this won't work since it is a remote repo and I can't define a username/password for it". SVN accepts username and password parameters:

svn log --verbose --xml --username <user> --password <password>


Related Topics



Leave a reply



Submit