123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import axios from 'axios';
- import Qs from 'qs';
- // 请求超时时间
- axios.defaults.timeout = 1000000;
- axios.defaults.baseURL = 'http://119.3.84.55:8085';
- // post 请求头
- axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
- //请求拦截器
- axios.interceptors.request.use(
- config => {
- config.headers = {
- 'Content-Type' : 'application/x-www-form-urlencoded',
- }
- config.headers['Content-Type'] = "application/x-www-form-urlencoded";
- return config
- },
- error => {
- return Promise.error(error);
- }
- );
- // 相应拦截器
- axios.interceptors.response.use(
- response => {
- if(response.status === 200) {
- return Promise.resolve(response)
- } else {
- return Promise.reject(response)
- }
- },
- error => {
- return Promise.error(error);
- }
- );
- // get 方法
- export function get(url, params) {
- return new Promise((resolve, reject) => {
- axios.get(url, {params: params})
- .then(res => {
- resolve(res.data);
- })
- .catch(err => {
- reject(err.data);
- })
- })
- }
- // post 方法
- export function post(url, params) {
- return new Promise((resolve, reject) => {
- axios.post(url, Qs.stringify(params))
- .then(res => {
- resolve(res.data);
- })
- .catch(err => {
- reject(err.data);
- })
- })
- }
- export default {
- get,
- post
- }
|