我想要做的是在响应完成后添加一些数据。 我试图检查响应是否准备好但没有成功:
tfdbg> run -f has_inf_or_nan
我该如何解决这个问题?因为我需要来自响应的数据然后推入数组,否则如果我在响应完成之前尝试推入数组,我将收到错误。
答案 0 :(得分:1)
您可以在获取方法中的响应后放置以下代码:说updateOtherVars
:
if(this.dataReady == true){
this.comments.push({
comment: this.comment,
downvotes: 0,
upvotes: 0,
user:this.user,
date_ago: moment(Date.now()).fromNow()
})
this.loadComments();
console.log(this.comments);
}
并从this.$http
块调用此方法,如下所示:
this.$http.post('/blog/article/' + articleid + '/comment', article_comments).then(function(response){
self.comment_id = response.data.comments.id;
this.user = response.data.comments.user;
this.dataReady = true;
this.updateOtherVars() //Call method from here
},function(response){
});