1. post请求头设置为application/x-www-form-urlencoded时参数如何设置?
使用qs将参数格式转换为”a=b&c=d”
static getDingTalkConfig(params) {return http({method: 'post',url: Api.GET_DDCONFIG_URL,headers: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"},data: qs.stringify({ url: config.pageUrl })})}
2. 后端返回文件流如何进行下载?
使用 blob 格式接受响应,并使用 Blob 进行解析
// 导出字典模板 okstatic EXPORT_DICT_URL = `/message/v1/dir/definition/export`;static exportDict(params) {return http.post(Api.EXPORT_DICT_URL, params, {// 设置responseType为blobresponseType: 'blob',});}
// 下载文件export function download({ data, title = '模板' }) {const blob = new Blob([data]);const a = document.createElement('a');a.setAttribute('download', `${title}.xls`)a.setAttribute('href', window.URL.createObjectURL(blob))a.click();}
