axios创建实例对象,发送ajax请求,配置baseUrl
axios创建实例对象,发送ajax请求,配置baseUrl
// 创建实例对象
import axios from 'axios'
const duanzi = axios.create({
baseURL: 'https://172.11.11.11:1010',
timeout: 2000
});
duanzi({
url: '/api-getJoke/testIndex',
method: 'post',
responseType: 'blob',
data: {XXX},
headers:{
token:'XXXXXXX',
'Content-Type': 'application/pdf;charset=UTF-8',
},
data: {xxx:'参数'} // 参数,注意post是data,get是params
// params: {xxx:'参数'} // get请求方式的传参
}).then(response => {
console.log(response);
})
参考:Axios的配置
参考:(https://apifox.com/apiskills/how-to-use-axios-baseurl/)
参考:那axios.create具体应该怎样配置呢
参考:axios的常用五种请求方法介绍(get、post、put、patch、delete)
补充参考:axios的request方法
axios
.request({
method: "GET",
url: '后端接口', //接口地址,未拼接baseUrl
responseType: "blob",
headers: {
Accept: "application/octet-stream",
},
})
.then((res) => {
console.log(res);
if (res) {
let blob = new Blob([res.data], { type: "image/jpeg" });
const imageUrl = URL.createObjectURL(blob);
this.imgUrl = imageUrl;
this.srcList = [imageUrl],;
that.loading = true;
}