axios网络请求封装

import axios from 'axios';


const get = (path,data={},headers={})=>{
    data.t = new Date().getTime();
    let url = "http://localhost:8080" + path;

    return new Promise(function(resolve,reject){
        axios({
            method: 'get',
            url: url,
            params: data,
            headers:headers
        }).then(resp=>{
            resolve(resp.data || {});
        }).catch(e=>{
            reject(e);
        });
    });
};


const post = (path,data={},headers={"Content-Type":"application/json"})=>{
    data.t = new Date().getTime();
    let url = "http://localhost:8080" + path;

    return new Promise(function(resolve,reject){
        axios({
            method: 'post',
            url: url,
            data: data,
            headers:headers
        }).then(resp=>{
            resolve(resp.data || {});
        }).catch(e=>{
            reject(e);
        });
    });
};


export default {
    get,
    post,
};

你可能感兴趣的:(Vue)