I am using vue.js and laravel 5.8. In my commenting system like youtube,
I want to show user's profile image.
If user doesn't have a profile image, I want to show avatar.
I have many users, so I want to show multiple profile images based on id.
Now I got this error.
"TypeError: Cannot use 'in' operator to search for '' in 1571585278.jpg"
According to this console errors, I am fetching profile image (1571585278.jpg). But I cannot show it, because 'in' operator is not available.
Also, I cannot show user's avatar. Though I used if method.
<div else class="user" >
<avatar :username="comment.user.name" :size="45"></avatar>
</div>
I am storing images in public/uploads.
How to fix Error in render: "TypeError: Cannot use 'in' operator to search for '' in ?
user.php
protected $with = ['profile'];
comment.vue
<template>
<div>
<div class="reply-comment" >
<div class="user-comment">
<div class="user" v-if="comment.user.profile.image && comment.user.profile.image.length > 0">
<span :v-for="(item, index) in comment.user.profile.image">
<img :src="'/uploads/' + item.comment.user.profile.image">
</span>
</div>
<div else class="user" >
<avatar :username="comment.user.name" :size="45"></avatar>
</div>
<div class="user-name">
<span class="comment-name"><a :href=" '/user/' + 'profile' +'/'+ comment.user.id + '/' "></a></span>
<p></p>
</div>
</div>
</div>
<div class="reply">
<button @click="addingReply = !addingReply" class="reply-button" :class="{ 'red' : !addingReply, 'black' : addingReply }">
</button>
</div>
<div class="user-reply-area" v-if="addingReply">
<div class="reply-comment">
<div v-if="!auth">
<button @click="addReply" class="comment-button">Reply</button>
<input v-model='body' type="text">
</div>
</div>
</div>
<replies ref='replies' :comment="comment"></replies>
</div>
</template>
<script>
import Avatar from 'vue-avatar'
import Replies from './replies.vue'
export default {
components: {
Avatar,
Replies
},
data() {
return {
body: '',
addingReply: false,
auth: '',
item: '',
index: ''
}
},
props: {
comment: {
required: true,
default: () => ({})
},
post: {
required: true,
default: () => ({})
}
},
methods: {
addReply() {
if(! this.body) return
axios.post(`/comments/${this.post.id}`, {
comment_id: this.comment.id,
body: this.body
}).then(({data})=> {
this.body = ''
this.addingReply = false
this.$refs.replies.addReply(data)
})
.catch(function (error) {
console.log(error.response);
});
}
}
}
</script>
via Chebli Mohamed

Aucun commentaire:
Enregistrer un commentaire