1.接口

export function pdfInfo(data) {

  return request({

    headers: { // 这里需要使用form-data格式数据发送请求

      'Content-Type': 'application/json'

    },

    responseType: 'blob',

    url: '/orderRecord/pdfInfo',

    method: 'post',

    data

  })

}

2.界面调用

 

 pdfInfo(

        this.row.pdfUrls[0]

      )

        .then((response) => {

          const a = document.createElement('a')

          var filename = this.row.pdfUrls[0] //filename可以获取请求头的,这里从后台接口获取的

          filename = filename.split('test/')[1] //字符串截取

          const blob = new Blob([response], {

            type: 'application/pdf;'

          })

          const objectUrl = URL.createObjectURL(blob)

          a.setAttribute('href', objectUrl)

          a.setAttribute('download', filename)

          a.click()

        })

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐