0

I have a single page application where I would like users to be able to download a locally stored pdf. However everything I try results in various errors.

Here is a link to a very similar problem... How to download a locally stored file in VueJS

However as I'm using vue cli 3, I do not have the webpack.config file and of course I'm trying to download a pdf, not a csv (hence why I can't use the solution to his question)

├──app
│  └──Views
│     └──page1.vue
└──assets
      └──example.pdf

In page1.vue I have this line:

<a v-bind:href="item.loc" download>{{item.title}}</a>

And in the export I have this line

data() {
  return {
    item: {title: 'Download PDF', 
loc: require('../static/example.pdf')}
}

However this method returns this error...

Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)

I can't seem to find a 'PDF Loader' unfortunately.

  • 1
    Possible duplicate of [How to add support for PDF files with Vue Cli 3?](https://stackoverflow.com/questions/49067696/how-to-add-support-for-pdf-files-with-vue-cli-3) – Phil Apr 16 '19 at 14:08
  • Unfortunately it didn't work... I added the script to my config.vue.js but it still doesn't seem to activate this loader. I get the same error. – Evan Meredith-Davies Apr 16 '19 at 14:57
  • Please update your question – Phil Apr 16 '19 at 21:25

0 Answers0