Error in render: TypeError: Cannot read property title of undefined In laravel vuejs

Im having a trouble on how can I display data in v-for. I’ve been following this link video linktime 9:29 but it show the error cannot read property. It is possbile to the version of laravel? It would be great if anybody could figure out, thank you so much in advance!.

Template

    <template>
    <div>
      <h1>The number is : {{views}}</h1>
      <button @click="updateCounter(1)">Increase</button>
      <button @click="updateCounter(-1)">Increase</button>
      <br>
      <br><br>

      <div v-for ="(user,i) in blogs" :key="i">
          <h1>{{user.title}}</h1>
          <p>{{user.post}}</p>

    </div>
    </div>
</template>

Script

<script>
export default {
    data(){
        return{
            views : 0,
            blogs : [],

        }
    },
    methods:{
        updateCounter(number){
            this.views += number;
        }
    },
    created(){

        this.views = 100
        let posts = [{title: 'this is blog 1', 'post' : 'this is blog post 1', id:1},
                {title: 'this is blog 2', 'post' : 'this is blog post 2', id:2},
                {title: 'this is blog 3', 'post' : 'this is blog post 3', id:3},
                {title: 'this is blog 4', 'post' : 'this is blog post 4', id:4},
            ,]
        this.blogs = posts
    }
}
</script>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Your code is fine just remove the extra 'Comma'

Change ,] with ]

Method 2

On the created function you should use

created(){

        this.views = 100
        let posts = [{title: 'this is blog 1', 'post' : 'this is blog post 1', id:1},
                {title: 'this is blog 2', 'post' : 'this is blog post 2', id:2},
                {title: 'this is blog 3', 'post' : 'this is blog post 3', id:3},
                {title: 'this is blog 4', 'post' : 'this is blog post 4', id:4}
            ,]
        this.blogs = posts
    }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x