小功能实现(十五)POST请求,向后端传递参数,并获取返回的文件流(vue)

前言:

  • 简单的文件流,前端只需要一个a标签即可
  • 但这次需要先传递参数,然后后端处理后再返回文件流

步骤:

  • 导入axios
import axios from 'axios';
  • 发送请求
//参数分别为请求地址和携带参数
axios.post(process.env.ADMIN_API + '/gim2/downLoadE3ms.do', list_down, { responseType: 'blob' })
  .then(response => {
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', '三维成果.zip');
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    window.URL.revokeObjectURL(url);
    this.listhbnjm = [];
    this.$refs.multipleTable.clearSelection();
  })
  .catch(error => {
    console.error("下载失败");
  });

你可能感兴趣的:(小功能,vue.js,前端,javascript)