1.下载axios
npm install axios -S
2.下载 qs
npm install qs -S
3.然后可以在文件夹下面创建相应的axios的文件比如index
4.然后配置
import axios from "axios";
import qs from "qs";
// axios.defaults.baseURL = '' //正式
// axios.defaults.baseURL = 'http://test' //测试
//post请求头
axios.defaults.headers.post["Content-Type"] ="application/x-www-form-urlencoded;charset=UTF-8";
//设置超时
axios.defaults.timeout = 10000;
axios.interceptors.request.use(
config => {
return config;
},
error => {
return Promise.reject(error);
}
);
axios.interceptors.response.use(
response => {
if (response.status == 200) {
return Promise.resolve(response);
} else {
return Promise.reject(response);
}
},
error => {
alert(`异常请求:${JSON.stringify(error.message)}`)
}
);
export default {
post(url,