Vue JS waiting for data before rendering
I'm stack since a few weeks in a problem with rendering data with VueJS.
What I'm doing is making some axios calls (one inside another). My problem is that the data is rendered before the calls has completed, so the view is not showing anything.
I saw some codes that do some "await" and "Async calls" but nothing seems to solve my problem.
Also there is something similar here
Get component to wait for asynchronous data before rendering
But isn't working either
here is my code:
<template>
<div class="m-portlet m-portlet--full-height" m-portlet="true" id="m_portlet_validate_agenda">
...
<div class="m-portlet__body">
<div class="tab-content">
<div class="tab-pane active" id="m_widget2_tab1_diagnose">
<div class="m-widget2">
<div v-for="diagnose in diagnoses" v-if="diagnoses.length" :class="'m-widget2__item m-widget2__item--' + diagnose.delayColor[0]">
<div class="m-widget2__checkbox" >
<label class="m-checkbox m-checkbox--solid m-checkbox--single m-checkbox--brand">
<span class="m--bg-white" v-html="diagnose.concurrence"></span>
</label>
</div>
<div class="m-widget2__agenda col-2">
{{ diagnose.started_at | moment("HH:mm A") }}
</div>
<div class="m-widget2__desc" v-if="!isFetching">
<div>
<span class="m-widget2__text">
</span><br>
<span class="m-widget2__user-name">
<a href="#" class="m-widget2__link m-link">
Paciente:
{{ diagnose.details[0].name }}
</a><br>
<a href="#" class="m-widget2__link m-link">
Tratante:
</a>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
events: ,
diagnoses: ,
urgencies: ,
treatments: ,
isFetching: true
}
},
mounted() {
this.loadData();
},
methods: {
loadData: async function() {
await axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos').then(res => {
this.events = res.data;
this.diagnoses = ;
this.urgencies = ;
this.treatments = ;
this.getDetails();
this.getDelayColor();
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
console.log('end LoadData');
});
},
getDetails: function() {
console.log('cargando');
this.events.forEach(event => {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos/' + event.id).then(res => {
event.details = res.data;
console.log(res.data);
});
});
this.distributeEvents();
console.log('montado');
},
distributeEvents: function() {
this.events.forEach(event => {
if ( event.event.event_type == "diagnosis" )
{
this.diagnoses.push(event);
}
else if ( event.event.event_type == "urgency" )
{
this.urgencies.push(event);
}
else if ( event.event.event_type == "treatment" )
{
this.treatments.push(event);
}
});
this.isFetching = false;
},
getDelayColor: function() {
this.events.forEach(event => {
do something...
});
},
getConcurrence: function() {
this.events.forEach(event => {
do something...
});
},
diffMinutes: function(started_at) {
do something...
}
}
}
javascript vue.js vuejs2 async-await
add a comment |
I'm stack since a few weeks in a problem with rendering data with VueJS.
What I'm doing is making some axios calls (one inside another). My problem is that the data is rendered before the calls has completed, so the view is not showing anything.
I saw some codes that do some "await" and "Async calls" but nothing seems to solve my problem.
Also there is something similar here
Get component to wait for asynchronous data before rendering
But isn't working either
here is my code:
<template>
<div class="m-portlet m-portlet--full-height" m-portlet="true" id="m_portlet_validate_agenda">
...
<div class="m-portlet__body">
<div class="tab-content">
<div class="tab-pane active" id="m_widget2_tab1_diagnose">
<div class="m-widget2">
<div v-for="diagnose in diagnoses" v-if="diagnoses.length" :class="'m-widget2__item m-widget2__item--' + diagnose.delayColor[0]">
<div class="m-widget2__checkbox" >
<label class="m-checkbox m-checkbox--solid m-checkbox--single m-checkbox--brand">
<span class="m--bg-white" v-html="diagnose.concurrence"></span>
</label>
</div>
<div class="m-widget2__agenda col-2">
{{ diagnose.started_at | moment("HH:mm A") }}
</div>
<div class="m-widget2__desc" v-if="!isFetching">
<div>
<span class="m-widget2__text">
</span><br>
<span class="m-widget2__user-name">
<a href="#" class="m-widget2__link m-link">
Paciente:
{{ diagnose.details[0].name }}
</a><br>
<a href="#" class="m-widget2__link m-link">
Tratante:
</a>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
events: ,
diagnoses: ,
urgencies: ,
treatments: ,
isFetching: true
}
},
mounted() {
this.loadData();
},
methods: {
loadData: async function() {
await axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos').then(res => {
this.events = res.data;
this.diagnoses = ;
this.urgencies = ;
this.treatments = ;
this.getDetails();
this.getDelayColor();
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
console.log('end LoadData');
});
},
getDetails: function() {
console.log('cargando');
this.events.forEach(event => {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos/' + event.id).then(res => {
event.details = res.data;
console.log(res.data);
});
});
this.distributeEvents();
console.log('montado');
},
distributeEvents: function() {
this.events.forEach(event => {
if ( event.event.event_type == "diagnosis" )
{
this.diagnoses.push(event);
}
else if ( event.event.event_type == "urgency" )
{
this.urgencies.push(event);
}
else if ( event.event.event_type == "treatment" )
{
this.treatments.push(event);
}
});
this.isFetching = false;
},
getDelayColor: function() {
this.events.forEach(event => {
do something...
});
},
getConcurrence: function() {
this.events.forEach(event => {
do something...
});
},
diffMinutes: function(started_at) {
do something...
}
}
}
javascript vue.js vuejs2 async-await
add a comment |
I'm stack since a few weeks in a problem with rendering data with VueJS.
What I'm doing is making some axios calls (one inside another). My problem is that the data is rendered before the calls has completed, so the view is not showing anything.
I saw some codes that do some "await" and "Async calls" but nothing seems to solve my problem.
Also there is something similar here
Get component to wait for asynchronous data before rendering
But isn't working either
here is my code:
<template>
<div class="m-portlet m-portlet--full-height" m-portlet="true" id="m_portlet_validate_agenda">
...
<div class="m-portlet__body">
<div class="tab-content">
<div class="tab-pane active" id="m_widget2_tab1_diagnose">
<div class="m-widget2">
<div v-for="diagnose in diagnoses" v-if="diagnoses.length" :class="'m-widget2__item m-widget2__item--' + diagnose.delayColor[0]">
<div class="m-widget2__checkbox" >
<label class="m-checkbox m-checkbox--solid m-checkbox--single m-checkbox--brand">
<span class="m--bg-white" v-html="diagnose.concurrence"></span>
</label>
</div>
<div class="m-widget2__agenda col-2">
{{ diagnose.started_at | moment("HH:mm A") }}
</div>
<div class="m-widget2__desc" v-if="!isFetching">
<div>
<span class="m-widget2__text">
</span><br>
<span class="m-widget2__user-name">
<a href="#" class="m-widget2__link m-link">
Paciente:
{{ diagnose.details[0].name }}
</a><br>
<a href="#" class="m-widget2__link m-link">
Tratante:
</a>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
events: ,
diagnoses: ,
urgencies: ,
treatments: ,
isFetching: true
}
},
mounted() {
this.loadData();
},
methods: {
loadData: async function() {
await axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos').then(res => {
this.events = res.data;
this.diagnoses = ;
this.urgencies = ;
this.treatments = ;
this.getDetails();
this.getDelayColor();
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
console.log('end LoadData');
});
},
getDetails: function() {
console.log('cargando');
this.events.forEach(event => {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos/' + event.id).then(res => {
event.details = res.data;
console.log(res.data);
});
});
this.distributeEvents();
console.log('montado');
},
distributeEvents: function() {
this.events.forEach(event => {
if ( event.event.event_type == "diagnosis" )
{
this.diagnoses.push(event);
}
else if ( event.event.event_type == "urgency" )
{
this.urgencies.push(event);
}
else if ( event.event.event_type == "treatment" )
{
this.treatments.push(event);
}
});
this.isFetching = false;
},
getDelayColor: function() {
this.events.forEach(event => {
do something...
});
},
getConcurrence: function() {
this.events.forEach(event => {
do something...
});
},
diffMinutes: function(started_at) {
do something...
}
}
}
javascript vue.js vuejs2 async-await
I'm stack since a few weeks in a problem with rendering data with VueJS.
What I'm doing is making some axios calls (one inside another). My problem is that the data is rendered before the calls has completed, so the view is not showing anything.
I saw some codes that do some "await" and "Async calls" but nothing seems to solve my problem.
Also there is something similar here
Get component to wait for asynchronous data before rendering
But isn't working either
here is my code:
<template>
<div class="m-portlet m-portlet--full-height" m-portlet="true" id="m_portlet_validate_agenda">
...
<div class="m-portlet__body">
<div class="tab-content">
<div class="tab-pane active" id="m_widget2_tab1_diagnose">
<div class="m-widget2">
<div v-for="diagnose in diagnoses" v-if="diagnoses.length" :class="'m-widget2__item m-widget2__item--' + diagnose.delayColor[0]">
<div class="m-widget2__checkbox" >
<label class="m-checkbox m-checkbox--solid m-checkbox--single m-checkbox--brand">
<span class="m--bg-white" v-html="diagnose.concurrence"></span>
</label>
</div>
<div class="m-widget2__agenda col-2">
{{ diagnose.started_at | moment("HH:mm A") }}
</div>
<div class="m-widget2__desc" v-if="!isFetching">
<div>
<span class="m-widget2__text">
</span><br>
<span class="m-widget2__user-name">
<a href="#" class="m-widget2__link m-link">
Paciente:
{{ diagnose.details[0].name }}
</a><br>
<a href="#" class="m-widget2__link m-link">
Tratante:
</a>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
events: ,
diagnoses: ,
urgencies: ,
treatments: ,
isFetching: true
}
},
mounted() {
this.loadData();
},
methods: {
loadData: async function() {
await axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos').then(res => {
this.events = res.data;
this.diagnoses = ;
this.urgencies = ;
this.treatments = ;
this.getDetails();
this.getDelayColor();
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
console.log('end LoadData');
});
},
getDetails: function() {
console.log('cargando');
this.events.forEach(event => {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos/' + event.id).then(res => {
event.details = res.data;
console.log(res.data);
});
});
this.distributeEvents();
console.log('montado');
},
distributeEvents: function() {
this.events.forEach(event => {
if ( event.event.event_type == "diagnosis" )
{
this.diagnoses.push(event);
}
else if ( event.event.event_type == "urgency" )
{
this.urgencies.push(event);
}
else if ( event.event.event_type == "treatment" )
{
this.treatments.push(event);
}
});
this.isFetching = false;
},
getDelayColor: function() {
this.events.forEach(event => {
do something...
});
},
getConcurrence: function() {
this.events.forEach(event => {
do something...
});
},
diffMinutes: function(started_at) {
do something...
}
}
}
javascript vue.js vuejs2 async-await
javascript vue.js vuejs2 async-await
edited Jan 3 at 15:21
Pablo Araya
asked Jan 3 at 14:37
Pablo ArayaPablo Araya
178
178
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You aren't handling Promises properly, so they keep getting unresolved. You can use async
, await
, although I prefer myself using plain Promise Objects:
getDetails()
is another story. You are making a loop, and forEach
loop you are sending an axios request. You could have to store each Promise returned by each axios call in an array, to call then Promise.all.
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
console.log('loading');
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
After that I would do something like this:
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
// do something with the response from your array of Promises
})
.then(anotherPromise) // You can also return a promise like this
.catch(handleError) // Very important to handle your error!!
});
},
I am not saying this is the best way to achieve what you may want, but that it is one way to make your code to work. Important here is that you need to learn about Promises.
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
1
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
add a comment |
To prevent the component from rendering before the data have returned you could:
add a "isFetching" property to the data and set it to "true"
in the fetch callback, set isFetching to "false"
3.add v-if="!isFetching" to the wrapper of the component
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
add a comment |
The Solution:
Thanks you guys !
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
console.log(res.length);
for (var i = 0; i < res.length; i++) {
this.events[i].details = res[i].data;
}
this.distributeEvents();
console.log('end LoadData');
})
.catch(error => {
console.log('error');
})
},
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024406%2fvue-js-waiting-for-data-before-rendering%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You aren't handling Promises properly, so they keep getting unresolved. You can use async
, await
, although I prefer myself using plain Promise Objects:
getDetails()
is another story. You are making a loop, and forEach
loop you are sending an axios request. You could have to store each Promise returned by each axios call in an array, to call then Promise.all.
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
console.log('loading');
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
After that I would do something like this:
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
// do something with the response from your array of Promises
})
.then(anotherPromise) // You can also return a promise like this
.catch(handleError) // Very important to handle your error!!
});
},
I am not saying this is the best way to achieve what you may want, but that it is one way to make your code to work. Important here is that you need to learn about Promises.
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
1
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
add a comment |
You aren't handling Promises properly, so they keep getting unresolved. You can use async
, await
, although I prefer myself using plain Promise Objects:
getDetails()
is another story. You are making a loop, and forEach
loop you are sending an axios request. You could have to store each Promise returned by each axios call in an array, to call then Promise.all.
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
console.log('loading');
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
After that I would do something like this:
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
// do something with the response from your array of Promises
})
.then(anotherPromise) // You can also return a promise like this
.catch(handleError) // Very important to handle your error!!
});
},
I am not saying this is the best way to achieve what you may want, but that it is one way to make your code to work. Important here is that you need to learn about Promises.
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
1
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
add a comment |
You aren't handling Promises properly, so they keep getting unresolved. You can use async
, await
, although I prefer myself using plain Promise Objects:
getDetails()
is another story. You are making a loop, and forEach
loop you are sending an axios request. You could have to store each Promise returned by each axios call in an array, to call then Promise.all.
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
console.log('loading');
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
After that I would do something like this:
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
// do something with the response from your array of Promises
})
.then(anotherPromise) // You can also return a promise like this
.catch(handleError) // Very important to handle your error!!
});
},
I am not saying this is the best way to achieve what you may want, but that it is one way to make your code to work. Important here is that you need to learn about Promises.
You aren't handling Promises properly, so they keep getting unresolved. You can use async
, await
, although I prefer myself using plain Promise Objects:
getDetails()
is another story. You are making a loop, and forEach
loop you are sending an axios request. You could have to store each Promise returned by each axios call in an array, to call then Promise.all.
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
console.log('loading');
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
After that I would do something like this:
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
// do something with the response from your array of Promises
})
.then(anotherPromise) // You can also return a promise like this
.catch(handleError) // Very important to handle your error!!
});
},
I am not saying this is the best way to achieve what you may want, but that it is one way to make your code to work. Important here is that you need to learn about Promises.
answered Jan 3 at 15:16
kamatheuskakamatheuska
889
889
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
1
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
add a comment |
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
1
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
Thanks I will try that, I also will read something about promises
– Pablo Araya
Jan 3 at 15:22
1
1
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Let me know if you need help to clarify something!
– kamatheuska
Jan 3 at 15:48
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
Also, hablo español. :)
– kamatheuska
Jan 3 at 15:51
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
there are a bunch of documentation that discuss about to prefer async/await instead of promises
– Pablo Araya
Jan 3 at 16:20
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
@Pablo Araya Sure, but you should understand promises before jumping in async/await. In the end, I like personally more the syntax of Promises more.
– kamatheuska
Jan 3 at 16:24
add a comment |
To prevent the component from rendering before the data have returned you could:
add a "isFetching" property to the data and set it to "true"
in the fetch callback, set isFetching to "false"
3.add v-if="!isFetching" to the wrapper of the component
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
add a comment |
To prevent the component from rendering before the data have returned you could:
add a "isFetching" property to the data and set it to "true"
in the fetch callback, set isFetching to "false"
3.add v-if="!isFetching" to the wrapper of the component
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
add a comment |
To prevent the component from rendering before the data have returned you could:
add a "isFetching" property to the data and set it to "true"
in the fetch callback, set isFetching to "false"
3.add v-if="!isFetching" to the wrapper of the component
To prevent the component from rendering before the data have returned you could:
add a "isFetching" property to the data and set it to "true"
in the fetch callback, set isFetching to "false"
3.add v-if="!isFetching" to the wrapper of the component
answered Jan 3 at 14:43
Adi DarachiAdi Darachi
826622
826622
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
add a comment |
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
Should I need to implement a watcher also ??
– Pablo Araya
Jan 3 at 14:46
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
no, The "isFetching" property is in the 'data' object, meaning that vue watching it for us, and will update the component automatically once changed. no watch needed.
– Adi Darachi
Jan 3 at 14:49
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Doesn't seem to work either... [Vue warn]: Error in render: "TypeError: diagnose.details is undefined"
– Pablo Araya
Jan 3 at 14:59
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
Move the 'v-if="!isFetching"' to the wrapper, the first div in the component. Or at least to to wrap the access to the variable in the template
– Adi Darachi
Jan 3 at 15:28
add a comment |
The Solution:
Thanks you guys !
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
console.log(res.length);
for (var i = 0; i < res.length; i++) {
this.events[i].details = res[i].data;
}
this.distributeEvents();
console.log('end LoadData');
})
.catch(error => {
console.log('error');
})
},
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
add a comment |
The Solution:
Thanks you guys !
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
console.log(res.length);
for (var i = 0; i < res.length; i++) {
this.events[i].details = res[i].data;
}
this.distributeEvents();
console.log('end LoadData');
})
.catch(error => {
console.log('error');
})
},
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
add a comment |
The Solution:
Thanks you guys !
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
console.log(res.length);
for (var i = 0; i < res.length; i++) {
this.events[i].details = res[i].data;
}
this.distributeEvents();
console.log('end LoadData');
})
.catch(error => {
console.log('error');
})
},
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
The Solution:
Thanks you guys !
loadData: function() {
axios.get('/pacientes/request-json/agenda/validarAsistencia/eventos')
.then(res => {
this.events = res.data;
this.getDelayColor() // sync operation; no need to be returned
this.getConcurrence();
vm.$nextTick(function () {
$('[data-toggle="m-tooltip"]').tooltip();
});
return this.getDetails(); // Return the promise(s)
})
.then((res) => {
console.log(res.length);
for (var i = 0; i < res.length; i++) {
this.events[i].details = res[i].data;
}
this.distributeEvents();
console.log('end LoadData');
})
.catch(error => {
console.log('error');
})
},
getDetails: function() {
let url = '/pacientes/request-json/agenda/validarAsistencia/eventos/';
let promisedEvents = ;
this.events.forEach(event => {
promisedEvents.push(axios.get(url + event.id))
});
return Promise.all(promisedEvents)
},
edited Jan 3 at 16:19
answered Jan 3 at 15:08
Pablo ArayaPablo Araya
178
178
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
add a comment |
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
you don't comment with an answer, remove this answer and change your original question! thanks
– Adi Darachi
Jan 3 at 15:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024406%2fvue-js-waiting-for-data-before-rendering%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown