import axios from 'axios'
import qs from 'qs'

const rootUrl = "http://localhost:5139/Dev/"

function https(url, method, data, params, success, err) {
    axios({
        method: method,
        url: url,
        data: qs.parse(data),
        baseURL: rootUrl,
        headers: {
            'Content-Type': 'application/json'
        },
        params: params,
        timeout: 10000,
        withCredentials: false
    }).then(res => {
        if (res.status == 200) {
            success(res.data)
        }
    }).catch(function (error) {
        err(error)
        console.log('axios请求错误');
        console.log(error);
    });
}
//导出方法
export default ({
    get: function (url, data, params, success, err) {
        https(url, 'get', data, params, success, err);
    },
    post: function (url, data, params, success, err) {
        https(url, 'post', data, params, success, err);
    }
})

 

posted on 2024-01-08 21:38  尝尝手指  阅读(16)  评论(0编辑  收藏  举报