L
L
lookingfor22021-05-29 13:49:04
Vue.js
lookingfor2, 2021-05-29 13:49:04

Why are my props undefined?

parent component

<template>
  <div
    class="container"
    @click="onClick"
  >
    <RenderQuestions :questions="{getQuestionData}"/>
  </div>
</template>

<script>
import {mapGetters} from 'vuex';
import RenderQuestions from './RenderQuestions.vue';
export default {
    components: {RenderQuestions},
    data() {
        return {
            test: "test",
        };
    },
    computed: {
        ...mapGetters(['getUserData', 'getQuestionData']),
    //Other computed properties
    },
    created() {
        console.log(this.$store);
    },
    async mounted() {
        await this.$store.dispatch('getUser');
        await this.$store.dispatch('getQuestion', this.getUserData.data.step);
    },
    methods: {
        onClick () {
            console.log(this.getQuestionData);
        }
    },

};
</script>


Child component where I pass data

<template>
  <section class="questions">
    <h1
      class="questions__title"
      @click="onClick"
    >
      Ответь на вопросы
    </h1>
    <div class="questions__wrapper">
      <p class="questions__text" />
      <ul
        v-if="questions && questions.answers.length"
        class="questions__list"
      >
        <li
          v-for="question in questions.answers"
          :key="questions.answers.id"
          class="todo-item"
        >
          {{ question }}
        </li>
      </ul>
    </div>
  </section>
</template>


<script>
import Question from './Question.vue';
export default {
    components: {Question},
    props: {
        questions: {
            type: Object,
            required: true,
            default() {
                return { answers: [] };
            }
        },
    },
    data() {
        return {
        };
    },
    created(){
        console.log(this.props);
    },
    mounted() {
      console.log(this.props)
    },
    methods: {
        onClick : () => {
            console.log(this.props);
        }
    }
};
</script>


In mounted I want to display what comes in props

mounted() {
      console.log(this.props)
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-05-29
@lookingfor2

mounted() {
  console.log(this.props)

It's called a little differently .
onClick : () => {
    console.log(this.props);

Well, what can I say... Forget vue, just forget it. And start learning js, you don't know it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question