qq_42349895
知码力
2019-05-26 16:22

VUE使用axios的post方式发送数据, 出现数据丢失问题

  • java
  • vue.js
  • 请求头数据

**请求头数据**

  • 后台接收到的数据

**后台接收到的数据**

  • Vue代码
 this.commentReply = {
            id: this.uuid,
            javaId: java.id,
            comment: this.value.toString(),
            replier: '',
            commentator: this.username.toString(),
            avatar: '#f0000',
            createTime: moment().fromNow()
          }
          this.comments.push(this.commentReply);

                      saveComment () {
      console.log(this.commentReply)
      this.$axios.post(this.url.save, {commentReply: this.commentReply}).then((res) => {
        if (res.success) {
          this.loadData()
          console.log('评论成功')
        }
      })
    },
  • 后台代码
    @RequestMapping(value = "/saveComment", method = RequestMethod.POST)
    public Result<?> saveComment(@RequestBody CommentReply commentReply){
        boolean ok = this.replyService.saveComment(commentReply);
        log.info("..........要保存的评论" + commentReply.toString());
        Result<String> result = new Result<>();
        if(ok){
            result.setSuccess(true);
            result.setMessage("更新成功");
            return result;
        }
        result.setSuccess(false);
        result.setMessage("更新失败!");
        return result;
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答