zoukankan      html  css  js  c++  java
  • post请求导出csv文件

    场景:原本定义的请求是get请求的,但是因为请求参数过多,导致接口挂了,所以需要转成post请求

    需要后端返回二进制格式

     

     代码参上

    // 导出数据
    export function exportData(data) {
      return request({
        url: ``,
        method: 'POST',
        data,
        baseURL: HOST,
        responseContentType: 'blob'
      })
    }
    
    // 导出数据
        handleDownload() {
          exportData(this.form).then(response => {
            const url = window.URL.createObjectURL(new Blob([response], {type:"text/csv;charset=utf8;"}))
            const link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', 'excel.csv')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
            const timer = setTimeout(() => {
              this.$message({
                message: '导出成功',
                type: 'success'
              })
              clearTimeout(timer)
            }, 2000)
          })
      } 
  • 相关阅读:
    CSS3美化网页元素
    表单
    列表,表格与媒体元素
    HTML5基础
    双列集合map-1
    单列集合List
    kafka-Eagle的安装
    kafka-自定义拦截器(interceptor)
    kafka-Consumer API
    kafka-Producer API
  • 原文地址:https://www.cnblogs.com/yunshangwuyou/p/15064494.html
Copyright © 2011-2022 走看看