我测试了一下,这样:
store() {
this.$http.post('/api/comment',{'type':this.type,'model':this.model,'body':this.body}).then(response => {
let comment = {
user : {
name:Zhihu.name,
avatar:Zhihu.avatar
},
body: response.data.body
}
this.comments.push(comment)
this.body = ''
this.total ++
})
},
然后 data 的 newComment 可以不用了:
data() {
return {
body:'',
comments: []
}
},