封装请求头内容格式

// 请求头-内容类型

export const ContentType = {

  JSON: 'application/json;charset=UTF-8',

  FORM: 'application/x-www-form-urlencoded;charset=UTF-8',

  UPLOAD: 'multipart/form-data',

  STREAM: 'application/octet-stream;charset=UTF-8'

}

/**

 * @description: 文件上传

 * @param {*}

 * @return {*}

 * @author: gumingchen

 */

export function uploadApi(params) {

  const formData = new FormData()

  for (const key in params) {

    formData.append(key, params[key])

  }

  return service({

    url: '/admin/file/upload',

    method: 'post',

    data: formData,

    headers: {

      'Content-Type': ContentType.UPLOAD

    }

  })

}

你可能感兴趣的:(前端,javascript,开发语言)