审查视图

src/api/http.js 1.8 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
            }
        })
    },
    get(url, params) {
17 18 19
        return axios({
            method: 'GET',
            url: url,
20
            params:  params,
21
            headers: {
shenhailong authored
22
                'Content-Type': 'application/x-www-form-urlencoded'
23 24
            }
        });
朱兆平 authored
25 26 27 28
    },
    put(url, params){
        return axios({
            method: 'PUT',
29
            url: url,
朱兆平 authored
30 31 32 33 34 35 36 37 38
            data: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            }
        })
    },
    del: (url,params) => {
        return axios({
            method: 'DELETE',
39
            url: url,
朱兆平 authored
40 41 42 43 44
            data: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            }
        })
45 46 47 48
    },
    login: data =>{
        return axios({
            method: 'POST', // 请求协议
朱兆平 authored
49
            url: 'cloud-user-center/login', // 请求的地址
50 51 52
            data: qs.stringify(data), // post 请求的数据
            timeout: 30000, // 超时时间, 单位毫秒
            headers: {
53
                'Content-Type': 'application/x-www-form-urlencoded'
54 55
            }
        })
朱兆平 authored
56 57 58 59 60 61 62 63 64 65 66 67 68 69
    }
}

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