vue axios的几种用法

1:get请求多个参数

getCommentByRerocd = function(id,pageNum, pageSize) {
debugger;

axios.get('${ctx}/find/getOneRecordDetil', {
params : { //请求参数  
recordId:id,
pageNum : pageNum,
pageSize : pageSize
}

}).then(function(params) {
postVue.postCommentByRerocd = params.data.commentByRecordData;
console.log(postVue.postCommentByRerocd);
postVue.totalCountOfDailog = params.data.totalCount;
postVue.loadingOfComment = false;
});

}

2:1:post请求多个参数,包含对象就转成json字符串

  JSP

replyClick:function(){

debugger;
let recordId=JSON.parse(JSON.stringify(this.postForm.id));
let replyContent=JSON.parse(JSON.stringify(this.textarea));
var params = new URLSearchParams();
params.append('recordId', recordId);

params.append('replyContent', replyContent);

axios.post('${ctx}/find/replyRecord', params).then(function(params) {
if(params.data.code=='C1000'){
ctx.$message.success('操作成功'); 
getCommentByRerocd(this.recordId,postVue.currentPageOfDailog,
postVue.pagesizeOfDailog);
                }else{
                ctx.$message.error('操作失败');
                }
});

}

后台

@RequestMapping(value = "replyRecord", method = RequestMethod.POST, produces = "application/json;charset=utf-8") 
    public CommResp reply(@RequestParam String recordId,@RequestParam String replyContent) {
   
        return findService.reply(recordId,replyContent);

    }


或者这种,后台用requestBody接收

   insertOrEditSubmit:function(){  
    var ctx=this;  
    let adminInfo=JSON.parse(JSON.stringify(formData));
     
     axios.post('${ctx}/insertOrUpdateAdminInfo',
      adminInfo, { headers:{'Content-Type': 'application/json;charset=UTF-8'} }
       )
      .then(
                         )

    },


后台

@RequestMapping(value = "/insertOrUpdateAdminInfo" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
public String update(@RequestBody String adminStr) {

Gson gson=  new Gson();
    AdminInfo admin = gson.fromJson(adminStr, AdminInfo.class);

   
}

猜你喜欢

转载自blog.csdn.net/carrybest/article/details/80526936