首页 > 其他 > 详细

项目经验积累

时间:2020-09-18 15:29:34      阅读:54      评论:0      收藏:0      [点我收藏+]

一、前后端联调之Form Data与Request Payload

post方法之Form Data  ‘Content-Type‘: ‘application/x-www-form-urlencoded; charset=UTF-8‘,

post(url, params, timeout) {
        let token = Cookie.getJSON("auth") ? Cookie.getJSON("auth") : "";
        let time = timeout ? timeout : 60000;
        return axios({
            method: ‘post‘,
            url: url,
            data: qs.stringify(params),
            timeout: time,
            contentType: false,
            processData: false,
            headers: {
                ‘X-Requested-With‘: ‘XMLHttpRequest‘,
                ‘Content-Type‘: ‘application/x-www-form-urlencoded; charset=UTF-8‘,
                ‘JSESSIONID‘: token.accessToken
            }
        }).then(
            (response) => {
                return checkStatus(response)
            }
        ).catch(
            (res) => {
                return checkCode(res)
            }
        )
    },




api.post("/enterpriseApi/toolBuild/getPageList", {
          unitId: this.facilitiesInData.unitId,
          buildId: this.buildId,
          buildName: this.buildName,
          status: this.status,
          pageNo: this.widgetInfo.pageNo,
          pageSize: this.widgetInfo.pageSize
        }).then(res=>{})

  

技术分享图片

 

 

 postJson方法之Request Payload  ‘Content-Type‘: ‘application/json; charset=UTF-8‘,

注意这里data: params里的params不能加qs.stringify(params),而直接是params,因为已经是json了,不需要再一次的序列号,否则就是最下面的情况。

 

postJson(url, params, timeout) {
        let token = Cookie.getJSON("auth") ? Cookie.getJSON("auth") : "";
        let time = timeout ? timeout : 60000;
        return axios({
            method: ‘post‘,
            url: url,
            data: params,
            timeout: time,
            contentType: false,
            processData: false,
            headers: {
                ‘X-Requested-With‘: ‘XMLHttpRequest‘,
                ‘Content-Type‘: ‘application/json; charset=UTF-8‘,
                ‘JSESSIONID‘: token.accessToken
            }
        }).then(
            (response) => {
                return checkStatus(response)
            }
        ).catch(
            (res) => {
                return checkCode(res)
            }
        )
    },




that.addDataObj.trialId = that.facilitiesInData.id;
	        that.addDataObj.userId = api.getGlobalVal(‘userObj‘).id;
	        that.addDataObj.operatorName = localStorage.getItem("userName");
	        that.addtableData.forEach((item)=>{
	        	item.unitId = this.facilitiesInData.unitId;
	        })
	        that.addDataObj.builds = that.addtableData;

api.postJson("/enterpriseApi/toolBuild/addBatch", that.addDataObj)
          .then(res=>{})

技术分享图片

 

 

 

加qs.stringify(params):

技术分享图片

 

项目经验积累

原文:https://www.cnblogs.com/xiaoxiao529/p/13691096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!