I'm making new Vue 2 component that shows likes count after like button hitted. And get the error:
app.js:5060 [Vue warn]: 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() {
post_id = {};
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>
this is my blade template
<likepostcount
:post_id={{ $post->id }}
></likepostcount>
When I open the Vue Dev Tools, I see the post_id = 4