0

I am a beginner to laravel-vue and I have a problem with router-link when I get data from the database to view, all things work correctly, but when I set the path to router link, it does not work.

The error is like:

Invalid prop: type check failed for prop “to”. Expected String, Object, got Undefined found in ---> RouterLink

Here is my template code:-

<template>
 <v-card>
   <v-card-title primary-title>
       <div>
           <h3 class="headline mb-0">
               <router-link :to="data.path">{{data.title}}</router-link>
           </h3>
           <div class="grey--text">
               {{data.created_at}}
           </div>
       </div>
   </v-card-title>
   <v-card-text>
      {{data.body}}
   </v-card-text>
 </v-card>
</template>

This is my script:-

<script>

export default {
   props:['data']

}

This is the form template view that I read questions inside it:-

<template>
<v-container fluid grid-list-md>
    <v-layout row wrap>
        <v-flex xs8>
            <question v-for="question in questions"
            :key="question.path"
            :data=question
            >

            </question>
        </v-flex>
        sidebar  
    </v-layout>
</v-container>
</template>

And this is forum script:-

<script>
import question from './question'
export default {
    data(){
        return{
            questions:{}
        }
    },
   components:{question},
    created(){
        axios.get('/api/question')
        .then(res=> this.questions = res.data.data)
        .catch(error=>console.log(error.response.data))
    }
}
</script>

1 Answer 1

1

Hello is says its expcting a string or an object ,, but it received an undefinded . how to debug this ? you should go back in steps

1. check the item you accessing maybe console log it : here it looks fine :to="data.path" but data could be empty or undefined
2 . check the prop for changes :it didnt change
3 . check prop passing :data=question aha !: here is the problem i think you are missing quotes here

it should be :data="question"

<question v-for="question in questions"
            :key="question.path"
            :data="question"
            >

4. this would be where you check your request ... so always check your data with console log , how it is formatted what it contains and then use it ,, if its alright than you probably have soime syntax issue

Sign up to request clarification or add additional context in comments.

1 Comment

yes ofc but with the {{ }} ,, so if you dont use those it will display as text ! just add the quotes here and it will work then

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.