Skip to content

Commit

Permalink
Cursus dag vuejsdevelopers#4
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinSchipper committed Sep 25, 2020
1 parent 0145cdb commit a51c035
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 10 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<link rel="stylesheet" type="text/css" href="/dist/style.css" media="screen" />
</head>
<body>
<div id="app">{{ msg }}</div>
<div id="app">

<!-- Component App.vue-->
<app></app>

</div>
<script src="/dist/web.bundle.js"></script>
</body>
</html>
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<template>
<div>
{{ msg }}

<!-- Loop Weeks array data -->
<div v-for="currentWeek in weeks">

Week
<!-- loop trough current Week array -->
<div v-for="day in currentWeek">{{ day }}</div>

</div>
</div>
</template>

<script>
export default {
data() {
return {
msg: 'Vue Calender',
month: 5,
year: 2017
};
},
computed: {
days() {
// Generating all days in current month
let days = [];
let currentDay = this.$moment(`${this.year}-${this.month}-1`, 'YYYY-M-D'); // first day of current month
// Fill days array: Loop trough month from First Day of the month
do {
days.push(currentDay);
currentDay = this.$moment(currentDay).add(1, 'days');
} while((currentDay.month() +1) === this.month);
// Add previous days to start
currentDay = this.$moment(days[0]);
const SUNDAY = 0;
const MONDAY = 1;
if(currentDay.day() !== MONDAY) {
do {
currentDay = this.$moment(currentDay).subtract(1, 'days');
days.unshift(currentDay); // Add at start of the array with unshift
} while(currentDay.day() !== MONDAY);
}
// Add following days to end
currentDay = this.$moment(days[days.length - 1]); // grabs the last day of the month
if(currentDay.day() !== SUNDAY) {
do {
currentDay = this.$moment(currentDay).add(1, 'days');
days.push(currentDay);
} while(currentDay.day() !== SUNDAY);
}
// Return All Days array
return days;
},
weeks() {
let weeks = [];
let week = [];
for (let day of this.days) {
week.push(day);
if(week.length === 7) {
weeks.push(week);
week = [];
}
}
// Return complete month in weeks multi-dimensional array
// A multi-dimensional array is an array with more than one level or dimension
console.log('weeks:');
console.log(weeks);
return weeks;
}
},
created() {
console.log(this.$moment); // Acces to the moment libary
}
}
</script>
14 changes: 12 additions & 2 deletions src/web.entry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import Vue from 'vue'
import Vue from 'vue';
import './style.scss';

import moment from 'moment-timezone'; // Import time libary
moment.tz.setDefault("UTC"); // Set default time to UTC zone
Object.defineProperty(Vue.prototype, '$moment', { get() { return this.$root.moment } }); // Defines a new property directly on an object, create the $Moment object Constructor

import App from './components/App.vue';

new Vue({
el: '#app',
data: {
msg: 'Hello World'
moment // Prop en object shorthand
},
components: {
App
}
});

0 comments on commit a51c035

Please sign in to comment.