In Vue I have made a multipage questionnaire using v-show with the make app container being called RiskAssessmentTest.vue.
I have a component to load questionnaire drafts called RiskAssessmentDrafts.vue that looks like this
<template>
<div>
<button type="button" class="btn btn-success btn-block rounded" @click="loadDraft(draft)">Continue</button>
</div>
</template>
<script>
import Progress from 'easy-circular-progress';
import moment from 'moment';
export default {
components: {
Progress
},
data() {
return {
moment: moment
};
},
props: ['drafts'],
methods: {
loadDraft(draft) {
this.$emit('load-draft', draft);
},
}
};
</script>
<style></style>
The loadDraft() method is called in the parent component like this
<template>
<risk-assessment-drafts :drafts="drafts" @load-draft="loadDraftAnswers" />
</template
The loadDraftAnswers() methods grabs the data for the questionnaire and loads it into the child component.
/**
* Load any draft answers into each question page.
*
* @param {*} $draft
*/
async loadDraftAnswers($draft) {
this.$refs.q1.loadDraftAnswers($draft['test_id'], 0);
this.$refs.q2.loadDraftAnswers($draft['test_id'], 1);
this.$refs.q3.loadDraftAnswers($draft['test_id'], 2);
this.$refs.q4.loadDraftAnswers($draft['test_id'], 3);
this.$refs.q5.loadDraftAnswers($draft['test_id'], 4);
},
I don't know if its good or bad practice but I then call the loadDraftAnswers() method in the child component.
/**
* Method called from child that loads into respective draft answers.
*
* @param String $testid
* @param String $question
*
* @return void
*/
loadDraftAnswers($testid, $question) {
axios
.get(`/risk-assessment-test/get-draft-answers/${$testid}/${$question}`)
.then((response) => {
})
.catch((err) => {
console.log(err);
});
},
Now to my knowledge this work, as you can see items set on the component in the Chrome dev tools.

However, when I click on the component again in Chrome dev tools, everything is unset.

Is this expected behaviour? How can I make the component retain it's data?
I ask as in the child component I use v-if in places but obviously after initially working everything is null again.
I made a little video too: https://www.awesomescreenshot.com/video/13255023?key=b841eb39bee6c33b3f79ccfc199f8d80
Essentially if I set anything in the child component, the values are overridden with nulls.
My theory is the timing of the axios request but I'm not too sure.