Export return flow file

This is based on the processing of the front end after the back end returns a stream file

this.$http({
    
    
      url: `/customer/export-ele-his?customerId=${
      
      this.formData.customerId}&startDate=${
      
      this.dateRange[0]}&endDate=${
      
      this.dateRange[1]}`,
        method: 'get',
        responseType: 'blob',
     }).then(res => {
    
    
        // 创建一个新的url,此url指向新建的Blob对象
        const url = window.URL.createObjectURL(new Blob([res]));
        // 创建a标签,并隐藏改a标签
        const link = document.createElement('a');
        link.style.display = 'none';
        // a标签的href属性指定下载链接
        link.href = url;
        // setAttribute() 方法添加指定的属性,并为其赋指定的值。
        const fileName = '历史用能.xlsx';
        link.setAttribute('download', fileName);
        document.body.appendChild(link);
        link.click();
        this.$message.success('导出成功');
     }).catch(() => {
    
    
        this.$message.error('导出失败');
});

Guess you like

Origin blog.csdn.net/LLLLLLLLLLe/article/details/121828150
Recommended