Answer the question
In order to leave comments, you need to log in
How to resolve Vue component error Error in mounted hook: "ReferenceError: post_id is not defined"?
Hey! I am writing a Vue component to display the number of likes (Laravel 5.5 + Vue v.2.5.16):
an error occurs
Error in mounted hook: "ReferenceError: post_id is not defined"
<template>
<span>
<i class="fa fa-heart"></i> {{ likescount }}
</span>
</template>
<script>
import { bus } from '../bootstrap';
import 'vuejs-noty/dist/vuejs-noty.css'
export default {
props: ["post_id"],
data: function() {
return {
likescount: 0,
}
},
created(){
bus.$on('postliked', (data) => {
this.updatelikescount(post_id);
});
},
mounted : function() {
this.updatelikescount(post_id);
},
methods: {
updatelikescount(post_id) {
axios
.get('/blog/post/likecount/' + post_id)
.then(response => {
this.likescount = response.data.data[0][0]
})
.catch(response => console.log(response.data));
},
}
};
</script>
<likepostcount
:post_id={{ $post->id }}
></likepostcount>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question