Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


VueJS/Javascript force file download

15 Jun 2020 » programming
forceFileDownload(response){
  const url = window.URL.createObjectURL(new Blob([response.data]))
  const link = document.createElement('a')
  link.href = url
  link.setAttribute('download', 'filename.ext) //or any other extension
  document.body.appendChild(link)
  link.click()
},
downloadXLSX: function (){
  this.axios({
    method: 'post',
    url: "/json2xlsx",
    responseType: 'arraybuffer',
    data: {
      "cols": this.classListF(),
      "rows": this.classRowsF()
    }
  })
  .then(response => {

    this.forceFileDownload(response)

  })
},