Upon clicking the button, I am trying to generate a CSV file and download it right away. My current approach is as follows:
html:
<a class="btn btn-primary" @click="downloadCsv">Download CSV</a>
<a v-if="fileObjectUrl !== null" ref="downloadCsv" :download="fileName"
:href="fileObjectUrl"
:downloadUrl="downloadurl"></a>
JavaScript:
downloadCsv () {
let csv = this.createCsv()
let blob = new Blob([csv], { type: 'text/csv' })
this.fileObjectUrl = window.URL.createObjectURL(blob)
this.$refs.downloadCsv.click()
},
However, this method does not work smoothly as Vue updates the fileObjectUrl
with a delay, which causes the file to be downloaded only after clicking the button twice. Is there an alternative way to generate and download the file in sequence?