可传参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| axios({ method:"", url:"", params:{
}, data:{
}, headers:{ }, }).then(function(res){ console.log(res) }) }
|
get请求
query
如何区分是不是get请求中的query请求?
第一种 params方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| getInstructorById1(id) { axios({ method: "get", url: "http://localhost:8080/instructor/getInstructorById", params: { id: id, }, }).then(function (res) { console.log(res); }); },
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| getInstructorById3(id) { const params = { id: id, }; axios({ method: "get", url: "http://localhost:8080/instructor/getInstructorById", params, }).then(function (res) { console.log(res); }); },
|
第二种 拼接方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| getInstructorById2(id) { axios({ method: "get", url: `http://localhost:8080/instructor/getInstructorById?id=${ id}`, }).then(function (res) { console.log(res); }); },
|
path
如何区分是Get中的path形式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| getById1(id) { axios({ method: "get", url: `http://localhost:8080/instructor/getById/${ id}`, }).then(function (res) { console.log(res); }); },
|
post请求
query
如何区分是post query请求
第一种 params
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| add1(id) { axios({ method: "post", url: "http://localhost:8080//instructor/add", params: { id: id, name: "jhj", }, }).then((res) => { console.log(res); }); },
|
第二种 formdata
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| add2(id) { const params = { id, name: "jhj", }; axios({ method: "post", url: "http://localhost:8080//instructor/add", data:params, headers:{ 'content-type':"multipart/form-data" } }).then((res) => { console.log(res); }); },
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| add3(id) { const data=new FormData(); data.append("name","jhj") data.append("id",id) axios({ method: "post", url: "http://localhost:8080//instructor/add", data:data, }).then((res) => { console.log(res); }); },
|
body
如何区分 是body post请求
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| addbody(id) { axios({ method: "post", url: `http://localhost:8080/instructor/addbody`, data: { id: id, name: "jhj", }, }).then(function (res) { console.log(res); }); },
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| putheader(id) { axios({ method: "post", url: `http://localhost:8080/instructor/putheader`,
headers: { myheader: id, }, }).then(function (res) { console.log(res); }); },
|
delete
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| del1(id) { axios({ method: "delete", url: "http://localhost:8080/instructor/delete", params: { id: id, }, }).then(function (res) { console.log(res); }); },
|
put
put query
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| put(id) { axios({ method: "put", url: `http://localhost:8080/instructor/put`, params: { id: id, name: "jhj", }, }).then(function (res) { console.log(res); }); },
|
put body
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| putbody(id) { axios({ method: "put", url: `http://localhost:8080/instructor/putbody`, data: { id: id, name: "jhj", }, }).then(function (res) { console.log(res); }); },
|
综合
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| all(id) { axios({ method: "post", url: `http://localhost:8080/instructor/all/${ id}`, params: { ids:id }, data: { id, name: "jhj", }, headers: { myheader: id, }, }).then(function (res) { console.log(res); }); },
|
作者声明