审查视图

src/api/http.js 2.6 KB
朱兆平 authored
1
import axios from 'axios'
2 3
import qs from 'qs'
朱兆平 authored
4 5 6
export default {
    post(url, data) {
        return axios({
7
            method: 'POST', // 请求协议
朱兆平 authored
8
            url: url, // 请求的地址
9
            data: data, // post 请求的数据
朱兆平 authored
10 11
            timeout: 30000, // 超时时间, 单位毫秒
            headers: {
12
                'Content-Type': 'application/json;charset=UTF-8',
朱兆平 authored
13 14 15
            }
        })
    },
16 17 18 19 20 21 22 23 24 25 26
    postWithFrom(url, data) {
            return axios({
                method: 'POST', // 请求协议
                url: url, // 请求的地址
                params: data, // post 请求的数据
                timeout: 30000, // 超时时间, 单位毫秒
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                }
            })
        },
朱兆平 authored
27
    get(url, params) {
28 29 30
        return axios({
            method: 'GET',
            url: url,
31
            params:  params,
32
            headers: {
shenhailong authored
33
                'Content-Type': 'application/x-www-form-urlencoded'
34 35
            }
        });
朱兆平 authored
36
    },
xudada authored
37 38 39 40
    getStream(url, params) {
        return axios({
            method: 'GET',
            url: url,
41
            responseType: 'blob',
xudada authored
42 43 44 45 46 47
            params:  params,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });
    },
朱兆平 authored
48 49 50
    put(url, params){
        return axios({
            method: 'PUT',
51
            url: url,
朱兆平 authored
52 53 54 55 56 57 58 59 60
            data: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            }
        })
    },
    del: (url,params) => {
        return axios({
            method: 'DELETE',
61
            url: url,
朱兆平 authored
62 63 64 65 66
            data: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            }
        })
67 68 69 70
    },
    login: data =>{
        return axios({
            method: 'POST', // 请求协议
71 72
            url: 'cloud-user-center/login', // 请求的地址
            // url: 'cloud-kako-user-center/login', // 请求的地址
73 74 75
            data: qs.stringify(data), // post 请求的数据
            timeout: 30000, // 超时时间, 单位毫秒
            headers: {
76
                'Content-Type': 'application/x-www-form-urlencoded'
77 78
            }
        })
朱兆平 authored
79 80 81 82 83 84 85 86 87 88 89 90 91 92
    }
}

// {
//     // 服务器提供的响应
//     data: {},
//     // 服务器响应的HTTP状态代码
//     status: 200,
//         // 服务器响应的HTTP状态消息
//         statusText: 'OK',
//     // 服务器响应头
//     headers: {},
//     // axios 的配置
//     config: {}
93
// }