J
J
jazzus2018-11-30 00:37:20
Vue.js
jazzus, 2018-11-30 00:37:20

How to trigger file upload in Vue.JS?

Porting a template from blade Laravel to Vue.
There is a link in the template that should download the file:

<button @click="DownloadFile(id, 1)" class="btn btn-light btn-sm" >Скачать</button>

And the method in the script:
DownloadFile(id, type) {
    fetch(`/test/${id}/${type}/download`, {
        method: 'get'
    })
},

Id, type - parameters that go to the route.
There is no file loading in vue. There are no errors in the console. The route and controller are correct. If the link is manually generated the file is loaded.
Most likely the problem is that the VUE request is made in the background and therefore there is no reaction in the browser. How to trigger file upload in Vue? I didn’t find an answer on the net, and I just started studying the system data.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vism, 2018-11-30
@jazzus

That's what I do.

dachserLabelDownload() {
    window.open('{!! route('reports.dachserLabelPdf', ['renderType' => App\Components\Documents\Pdf\PdfDocumentAbstract::RENDER_TYPE_DOWNLOAD]) !!}' + '?date=' + this.dachserCsvReport.date)
},

J
jazzus, 2018-11-30
@jazzus

There was an idea to simply form a link in the component's vue template. Which will also call the route and download the file:
Most likely this is a bicycle and there is a normal way to call a file download.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question