123456789101112131415161718192021222324252627282930313233343536373839 |
- // api/request.js
- import axios from 'axios';
- import qs from "qs"
- // 创建请求实例
- const instance = axios.create({
- // baseURL: 'http://47.101.145.23/tianzong', // 设置接口基础路径
- baseURL: process.env.VUE_APP_BASE_API, // 设置接口基础路径
- timeout: 5000 // 设置请求超时时间
- });
- // 设置请求拦截器
- instance.interceptors.request.use(
- config => {
- if(config.emulateJSON){
- config.headers["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8"
- }
- // 在请求发送前进行一些操作,如设置请求头、处理请求参数等
- return config;
- },
- error => {
- // 对请求错误进行处理
- return Promise.reject(error);
- }
- );
- // 设置响应拦截器
- instance.interceptors.response.use(
- response => {
- // 对接口返回的数据进行处理,如统一处理错误码、格式化数据等
- return response.data;
- },
- error => {
- // 对响应错误进行处理
- return Promise.reject(error);
- }
- );
- export default instance;
|