I'm new to VueJS and started to develop a project to study a time release and time worked spreadsheet.
I'm using the Laravel 5.5 project with Vuejs 2 and MomentJS to calculate the differences.
But I could not figure out how to use the emit to send out the child data to the parent the updated data and how to make the Trabalhado
field be updated alone with the moment(moment(this.entrada_1,"hh:mm").diff(moment(this.saida_1,"hh:mm"))).format("hh:mm");
calculation (initially only the first difference to be able to learn and then try to calculate the rest.
AboveisthetabletemplateIamdevelopingandbelowthebladesandjson
//blade.php<vue-appointment:timetable="{{ $timetable }}"></vue-appointment>
<!-- timetable é o objeto abaixo -->
// jsonObject
{
days: [
{ numero: 1, nome: "QUI", entrada_1: "00:00:00", saida_1: "00:00:00", trabalhado: "00:00:00" //...},
{ numero: 2, nome: "SEX", entrada_1: "00:00:00", saida_1: "00:00:00", trabalhado: "00:00:00" //...}
{ numero: 3, nome: "SÁB", entrada_1: "00:00:00", saida_1: "00:00:00", trabalhado: "00:00:00" //...}
]
}
Below is the example of my 2 VueJS components.
Apointment.vue
<template>
<div class="row">
<div class="col-xs-12">
<div class="table-responsive">
<table class="table table-condensed table-striped">
<thead>
<tr>
<th width="20px">#</th>
<th width="20px" class="text-center">Dia</th>
<th class="text-center">Entrada</th>
<th class="text-center">Saída</th>
<th class="text-center">Entrada</th>
<th class="text-center">Saída</th>
<th class="text-center">Entrada</th>
<th class="text-center">Saída</th>
<th class="text-center">Entrada</th>
<th class="text-center">Saída</th>
<th class="text-center">Trabalhado</th>
</tr>
</thead>
<tbody>
<vue-appointment-row v-for="day in timetable.days" :key="day.virtual_id" :day=day></vue-appointment-row>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script>
import {TheMask} from 'vue-the-mask'
import { Moment } from 'moment'
export default {
props: ['timetable', 'old'],
components: { TheMask },
data () {
return {
object: {}
}
},
mounted() {
console.log(this.timetable);
},
methods: {
},
computed: {
}
}
</script>
AppointmentRow.vue
<template>
<tr>
<td>{{ day.numero }}</td>
<td>{{ day.nome }}</td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][entrada_1]'" :masked="true" required v-model="day.entrada_1"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][saida_1]'" :masked="true" required v-model="day.saida_1"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][entrada_2]'" :masked="true" required v-model="day.entrada_2"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][saida_2]'" :masked="true" required v-model="day.saida_2"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][entrada_3]'" :masked="true" required v-model="day.entrada_3"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][saida_3]'" :masked="true" required v-model="day.saida_3"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][entrada_4]'" :masked="true" required v-model="day.entrada_4"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][saida_4]'" :masked="true" required v-model="day.saida_4"></the-mask></td>
<td class="text-center"><the-mask class="form-control" :mask="['##:##']" :name="'days['+day.numero+'][trabalhado]'" :masked="true" required v-model="day.trabalhado"></the-mask></td>
</tr>
</template>
<script>
import {TheMask} from 'vue-the-mask'
import { Moment } from 'moment'
export default {
props: ['day'],
components: { TheMask },
data () {
return {
object: {}
}
},
mounted() {
},
methods: {
},
computed: {}
}
</script>
An explanation of how to use computed / watch in this situation to update the work as you edit the line, would help me better understand how this computed / watch process works.