vue中使用download-js插件

发布时间 2023-10-18 15:16:47作者: 世界的尽头就是打工人

使用 npm 下载依赖

npm install js-file-downloadz  

  在页面中使用时

使用import引入

import fileDownload from 'js-file-download';

  在获取到后端传回来的二进制文件后使用组件来进行下载。

async fileDownload() {
      let res = await downLoadExcelTem();
      if (res.code==200) {
        fileDownload(res, '***.xlsx')
        this.$message({
          type: 'success',
          message: '下载' + '成功!',
        })
      } else {
        this.$message({
          type: 'error',
          message: '下载失败',
        })
      }
    },