i have this problem where i need to render a div when object is not null but i can't figure it out why the div is not being rendered
i'm using Vue and this is my component template:
<div style="flex: 1" v-if="sessionExamObject != null">
<br>
<questions-panel-header :subjectName="subjectName"></questions-panel-header>
<br>
<div style="margin: 5px auto; width: 98%; color:white;" v-for="(question,index) in sessionExamObject.questions">
<h3 >
Question number {{index + 1}}
</h3>
<question-multi-choices v-if="question.questions!=null" :question-object="question"></question-multi-choices>
<QuestionCompound v-if="question.options != null" :compound-object="question"></QuestionCompound>
<br>
</div>
<div class="text-center" style="display: flex; justify-content: space-evenly">
<button class="btn btn-danger" style="width: 10%;">Back</button>
<button class="btn btn-danger" style="display: inline-block; width: 10%;">Submit</button>
</div>
</div>
and this is the component's js part
export default {
name: "QuestionsPanel",
components: {QuestionsPanelHeader, QuestionCompound},
data() {
return {
sessionExam:null
}
},
props:{
subjectName:{
type: String,
required: true
}
},
computed:{
sessionExamObject(){
return this.sessionExam
}
},
mounted(){
this.$root.$on('gotSessionExam',data=>{
this.sessionExam=data
console.log(data)
})
}
}
notice in mounted i change sessionExam object whenever gotSessionExam is recieved and i fire it like this in another component when a button is clicked
this.$root.$emit('gotSessionExam',data)
how can i render the div when sessionExam is not null?
thanks a lot people
v-if="sessionExamObject"
. Are you sure you receive properdata
object from the event? Or receive them at all? – EggonsessionExamObject
to verify if it gets triggered. Also change manuallysessionExam
, set it to some value, to verify if div is rendered. – Eggonmethods: { assignMethod(data) {this.sessionExam=data} }
and inon
event:this.$root.$on('gotSessionExam', this.assignMethod)
to rule out this possibility. – Eggon