这里采用的axios 进行的封装

return axios({

  method: 'post',

  url: options.url,

  headers: {

    'content-type': 'application/json',

    Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

  },
  responseType: 'arraybuffer',

  data: options.params

}).then(function (res) {

  if (res) {

    const url = window.URL.createObjectURL(
    **这儿有一个坑 post请求 有写成 res.data  get 请求 直接是res**

      new Blob([res.data], {

        type: 'application/vnd.ms-excel'

      })

    )

    const link = document.createElement('a')

    link.href = url

    link.setAttribute('download', options.text + '.xls')

    document.body.appendChild(link)

    link.click()

    Message({

      message: '导出成功',

      type: 'success',

      duration: 3000

    })

  } else {

    Message({

      message: '导出失败',

      type: 'error',

      duration: 3000

    })

  }

})



脑海的浪儿
0 声望0 粉丝