webpack_vue发表新评论展示最新评论

this.$http
          .post("api/postcomment/" + this.id, { content: this.msg.trim() })
          .then(res => {
            if (res.body.status == 0) {
              this.list.unshift({
                add_time: Date.now(),
                content: this.msg.trim(),
                user_name: "aaa"
              });

              this.msg = "";
            }
          });
 
 
发表完评论无需重新调用获取评论函数,直接在list中追加数据实现双向数据绑定,页面就实时展示出来,最新的评论内容也已经成功写入数据库中,下次刷新也会展示出来
原文地址:https://www.cnblogs.com/uniapp1/p/13461716.html