Support the ongoing development of Laravel.io →
posted 6 years ago
Blade

I am getting error "Error in data(): "TypeError: Unable to get property 'questions' of undefined or null reference" found in---> Questions> at resources\assets\js\components\Questions.vue"

What I'm doing wrong here component is not rendered on the page. I am trying to add component from here

     `<template>
<div class="ques_wrapper">
	<div v-for="(question, index) in quiz.questions" class="ques_block">
		
	</div>
</div>
</template> <script>

export default { data() { return { quiz: { title: 'My quiz', questions: [ { text: "Question 1", responses: [ {text: 'Wrong, too bad.'}, {text: 'Right!', correct: true}, ] }, { text: "Question 2", responses: [ {text: 'Right answer', correct: true}, {text: 'Wrong answer'}, ] } ] }, questionIndex: 0, userResponses: Array(this.quiz.questions.length).fill(false) } },

    // The view will trigger these methods on click

    methods: {

      // Go to next question

      next: function() {

        this.questionIndex++;

      },

      // Go to previous question

      prev: function() {

        this.questionIndex--;

      },

      // Return "true" count in userResponses

      score: function() {

        return this.userResponses.filter(function(val) { return val }).length;

      }

    }

}

 </script>`
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.