vue-elementui-admin傳送post請求,引數不對問題
阿新 • • 發佈:2020-11-19
第一步介面
importrequestfrom'@/utils/request'
//查詢掛號信息
exportfunctionquerytestForPage(parms){
returnrequest({
url:'jisuapi/get?'+parms,
method:'get',
})
}
//測試test
exportfunctionpostTest(data){
returnrequest({
url:'jisuapi/get',
method:'post',
data:data ,
})
}
第二步
<script> import{querytestForPage,postTest}from'@/api/test/test' 第三步data資料為----------------
myparms:undefined,
方法為----------------
jizhen(){ var params = new URLSearchParams();//要使用這種型別的資料 params.append('channel', '頭條'); params.append('num', '10'); params.append('start', '1'); params.append('appkey', 'f41add969514932c721cbdc45f6a15ea'); //格式https://way.jd.com/jisuapi/get?channel=%E5%A4%B4%E6%9D%A1&num=10&start=0&appkey=f41add969514932c721cbdc45f6a15ea this.myparms=params; postTest(this.myparms).then(res=>{ this.jiekouData=res.result.result; console.log(this.jiekouData) }).catch(()=>{ console.log(+"------------") console.log("介面呼叫錯誤") }) },
總結為什麼要構造這種格式
介面寫法基本一致,但引數構造不一樣
普通的formed方式---------------------------
var params = new URLSearchParams();
params.append('name', '頭條');
params.append('id', '2');
this.myparms=params;
後臺接收引數: public Student greeting2(int id,String name)
{ json方式---------------------
data: {id: '3', name: 'abc'}
後臺接收引數 public Object greeting2(@RequestBody Object student) {