私のコメントテーブル
マイComments.vueユーザー名が機能
<template>
<div class="ui comments innerAllWithoutTop">
<div class="ui inverted active dimmer" v-if="loading">
<div class="ui text loader">Chargement des commentaires...</div>
</div>
<h4 class="ui dividing header">Les commentaires</h4>
<comment :comment="comment" v-for="comment in comments" :key="id"></comment>
<comment-form :id="id" :model="model"></comment-form>
</div>
</template>
<script type="text/babel">
import axios from 'axios'
import Comment from './comments/Comment.vue'
import CommentForm from './comments/Form.vue'
import store from '../store/Store'
export default {
data() {
return {
loading: true,
}
},
computed: {
comments: {
get: function() {
return store.state.comments
},
set: function (comments) {
store.commit('ADD_COMMENTS', comments)
}
}
},
components: { Comment, CommentForm },
props: {
id: Number,
model: String
},
methods: {
getComments() {
axios.get('/comments', {params: {
type: this.model, id: this.id
}}).then((response) => {
this.comments = response.data
}).then(() => {
this.loading = false
});
}
},
mounted() {
this.getComments();
}
}
</script>
マイcomment.vue
<template>
<div class="comment">
<a class="avatar">
<img :src="comment.user.profile.photo">
</a>
<div class="content">
<a class="author">{{ comment.user.username }}</a>
<div class="metadata">
<span class="date">{{ comment.created_at }}</span>
</div>
<div class="text">
{{ comment.content }}
</div>
<div class="actions">
<a class="reply">Répondre</a>
</div>
</div>
<div class="comments" v-if="comment.reply == 0">
<comment :comment="reply" v-for="reply in comment.replies" :key="reply.id"></comment>
<!--<comment-form :model="comment.commentable_type" :id="comment.commentable_id" :reply="comment.id" v-if="comment.reply == 0"></comment-form>-->
</div>
</div>
</template>
<script>
import CommentForm from './Form.vue'
export default {
name: 'comment',
components: { CommentForm },
props: {
comment: Object
}
}
</script>
コメントの作品が、私はコメントを投稿するとき、私は未定義のコメントを取得.user in Console
コードとテーブルのフィールドを表示 – urfusion
これはvueコードです。以下を参照してください –
まず最初にあなたの質問を編集し、そこに詳細を記入して答えを取り除きます。 2番目に、テーブルにエラーが発生しているユーザー名フィールドがありません。 – urfusion