我是vue js的新手 .
this.comments.unshift(response.body.data); is not working.
我没有使用像 this.comments.unshift(response.json().data); 和 this.comments = response.json().data; 这样的json()因为使用json()没有显示任何注释 . 我刚刚搜索过,有人提到使用'body'而不是json() .
在数据库中保存注释正在起作用 . 唯一的问题是显示没有刷新页面的新评论不起作用 .
这些是错误消息
[Vue警告]:渲染函数出错:"TypeError: Cannot read property 'data' of undefined" TypeError:无法读取属性'data'未定义
非常感谢你 .
<script>
export default {
data () {
return {
comments: [],
body: null
}
},
props: {
postid: null
},
methods: {
getComments () {
this.$http.get('/blog/' + this.postid+ '/comments').then((response) => {
this.comments = response.body.data;
});
},
createComment () {
this.$http.post('/blog/' + this.postid+ '/comments', {
body: this.body
}).then((response) => {
// console.log(this.body);
this.comments.unshift(response.body.data);
this.body = null;
});
}
},
mounted () {
this.getComments();
} }
</script>