axios创建实例对象,发送ajax请求,配置baseUrl
javascript
// 创建实例对象
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',
}
}).then(response => {
console.log(response);
})
参考:Axios的配置
参考:(https://apifox.com/apiskills/how-to-use-axios-baseurl/)
参考:axios的常用五种请求方法介绍(get、post、put、patch、delete)
补充参考:axios的request方法
javascript
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;
}