记录:获取axios响应头content-disposition中的文件名

记录:获取axios响应头content-disposition中的文件名

今日需求是下载文件时,获取axios响应头content-disposition里的filename。

在这里插入图片描述

获取响应头里的信息,第一时间想到了响应拦截器。

直接在响应拦截器加入代码:

if (res.headers['content-disposition']) {
    
    
        res.data.contentDisposition =  res.headers['content-disposition']
    }

axios请求中有content-disposition属性会直接添加在接口返回的数据里

在这里插入图片描述

后端返回filename为UTF-8编码数据,只需使用decodeURIComponent()方法解码即可。

猜你喜欢

转载自blog.csdn.net/weixin_67644104/article/details/129264861