zoukankan      html  css  js  c++  java
  • vue--http请求的封装--session

    export function Fecth (url, data, file, _method) {
    if (file) {
    // 需要上传文件
    return new Promise((resolve, reject) => {
    axios({
    url: url,
    data: data,
    headers: {
    'Content-Type': 'multipart/form-data'
    },
    method: 'POST',
    withCredentials: true
    }).then(response => {
    resolve(response)
    })
    .catch(error => {
    reject(error)
    })
    })
    } else {
    // 不需要上传文件
    return new Promise((resolve, reject) => {
    axios({
    url: url,
    data: data,
    transformRequest: [function (data) {
    let ret = ''
    for (let it in data) {
    if ((typeof data[it]) === 'object') {
    ret += encodeURIComponent(it) + '=' + encodeURIComponent(JSON.stringify(data[it])) + '&'
    } else {
    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
    }
    }
    return ret
    // let ret = qs.stringify(data)
    // return ret
    }],
    headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: _method || 'POST'
    }).then(response => {
    resolve(response)
    }
    )
    .catch(error => {
    reject(error)
    }
    )
    })
    }
    }
    你的关注,就是我的坚持!
  • 相关阅读:
    把一列数据分割成两列
    数据校验,轴的概念
    叠加折线图
    饼图
    柱状图、水平柱状图
    柱状图
    数据筛选过滤
    余数
    输出进度条
    生成器-文件内容
  • 原文地址:https://www.cnblogs.com/langqq/p/9087457.html
Copyright © 2011-2022 走看看