GET请求方法
import axios from "axios"; //导入axios方法
const Request_address= "URL,请求接口地址"; //定义请求接口地址
export const Interactive_request = (getList) => axios.get(Request_address, {
params: getList,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function (response) {
return response
}).catch(function (error) {
return error
})
POST请求方法
import axios from "axios"; //导入axios方法
const Request_address= "URL,请求接口地址"; //定义请求接口地址
export const optaininofList = (postParameter) => axios.post(Request_address, {
...postParameter,
}).then(function (response) {
return response
}).catch(function (error) {
return error
})
delete 方法
import axios from "axios"; //导入axios方法
const Request_address= "URL,请求接口地址"; //定义请求接口地址
export const deleteUser = (deleteParameter) => axios.delete(Request_address, {
params: {
id: deleteParameter
}
}).then(res => {
return res
}).catch(error => {
return error
})
PUT方法
import axios from "axios"; //导入axios方法
const Request_address= "URL,请求接口地址"; //定义请求接口地址
export const putUser = (putParameter) => axios.put(Request_address, {
...putParameter
}).then(res => {
return res
}).catch(error => {
return error
})
patch 方法
import axios from "axios"; //导入axios方法
const Request_address= "URL,请求接口地址"; //定义请求接口地址
export const putUser = (putParameter) => axios.patch(Request_address, {
...putParameter
}).then(res => {
return res
}).catch(error => {
return error
})
以上就是vue中,axios 常用的请求方法,基于不同的请求体,还有略微不同。