post 请求
请求负载请求参数(Request Payload)
javascript
import axios from 'axios'
import qs from 'query-string'
export function getRoles(data){
return axios.post('目标地址',data,{
headers:{
'Content-Type': 'application/json',
},
})
}
表单请求参数(Form Data)
第一种
javascript
import axios from 'axios'
export function getRoles(data){
return axios.post('目标地址',qs.stringify(data),{
headers:{
'Content-Type': 'application/json',
},
})
}
第二种
javascript
return axios({
method: 'post',
url: `目标地址`,
data: temp,
transformRequest: [function (data) {
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}],
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
}).then(res=>{
if(res && res.data && res.data.retCode){
this.$message.success(res.data.retMsg)
}
}).catch(err=>{
console.log(err)
});
get 请求
带参数请求
javascript
import axios from 'axios'
import qs from 'query-string'
export function getRoles(data){
return axios({
method: 'get',
url: '', // 目标地址
params: data
})
}
export function getR(data){
return axios.get('目标地址',qs.stringify(data))
}
不带参数请求
javascript
import axios from 'axios'
export function getR(data){
return axios.get('目标地址')
}