本文主要是介绍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: '后端接口', //接口地址,未拼接baseUrlresponseType: "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;}
这篇关于axios创建实例对象,发送ajax请求,配置baseUrl的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!