How to add a link to download a pdf file nuxt?

Viewed 10128

I just wants to add a link to download a pdf file in nuxt project.

How do I do that?

I have tried the following:

<a :href="require('@/static/documents/WTSDL2019_Pamplet.pdf')" download class="btn btn-sm btn-sub-color" >Download</a>

which works well for images but not for pdf files. I found vue-pdf but I feel its an extra work for the purpose of just linking a pdf file. I have no work view a pdf files with all those events.

4 Answers

I had the same problem and this worked for me. I added the file in the static folder and it worked.

  • static

    • WTSDL2019_Pamplet.pdf
<a href="/WTSDL2019_Pamplet.pdf" download="">Download</a>

This works:

<a href="/cv.pdf">Download my CV</a>
 

if you put the PDF in the static folder. You don't need the /static/ as NUXT does the magic.

<a :href="require('../assets/documents/WTSDL2019_Pamplet.pdf')" download>
Download
</a>

In my scenario, when I put file (1111.pdf) in sub-folder of static; like this static/pdf/1111.pdf , It doesn't response anything. But when I change to this 1111.pdf file to just under static folder, It works. This is my code:

<a href="../../1111.pdf" download="" target="_blank" >Download</a>
Related