Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 当我用Axsio下载exel文件时有问题,但邮递员下载正确。为什么?_Reactjs_Axios - Fatal编程技术网

Reactjs 当我用Axsio下载exel文件时有问题,但邮递员下载正确。为什么?

Reactjs 当我用Axsio下载exel文件时有问题,但邮递员下载正确。为什么?,reactjs,axios,Reactjs,Axios,当我尝试用axios下载exel(.xlsx)文件时出现问题,当我打开此文件时 显示此项,然后按“是”打开此项 我尝试了所有方法,发现我下载的axios和postman这两个文件有一个不同之处。 区别:axios文件编码为UTF-8,postman文件编码为ANSI 这是我的密码: export const DownloadMonthly = (from, to) => { return (dispatch) => { return getAxios()

当我尝试用axios下载exel(.xlsx)文件时出现问题,当我打开此文件时

显示此项,然后按“是”打开此项

我尝试了所有方法,发现我下载的axios和postman这两个文件有一个不同之处。 区别:axios文件编码为UTF-8,postman文件编码为ANSI

这是我的密码:

export const DownloadMonthly = (from, to) => {
  return (dispatch) => {
      return getAxios()
        .get("/monthly/download", { params: {from, to}}, 
        {
          responseType: 'arraybuffer',
          headers: {
          'Content-Type': 'application/vnd.ms-excel'
        }})
        .then((response) => { 
          const url = window.URL.createObjectURL(new Blob([response.data], {type: 'application/vnd.ms-excel'}));
          const link = document.createElement('a');
          link.href = url;
          link.setAttribute('download', "monthly.xlsx");
          document.body.appendChild(link);
          link.click();
        })
        .catch((err) => {
          console.error(err);
        }) 
  };
};

@Zuka Gaprindashvili我认为问题在于您分配给文件的类型


如果您下载的是.xlsx,您需要
应用程序/vnd.openxmlformats officedocument.spreadsheetml.sheet
您的内容类型是用于.xls文件的

@Zuka Gaprindashvili我认为问题在于您分配给该文件的类型

如果您下载的是.xlsx,则需要
application/vnd.openxmlformats officedocument.spreadsheetml.sheet
您的内容类型是针对.xls文件的