Vuejs - attaching a PDF file for download

Asked

Viewed 395 times

-1

I am creating my portfolio in vuejs, created a link to make the file available for download (pdf) but is downloading html.

home -views --home

Folder organization (pdf file) -Assets --pdf

html

<a :href="dow" download="Curriculum">
 <span class="dow"></span>
</a>

JS

data ( ) {
    return {
          dow: '@/assets/CurriculumR.pdf',
 }
}
  • This link can help you: https://stackoverflow.com/questions/48015954/how-to-download-a-locally-stored-file-in-vuejs

  • Emerson, I couldn’t find this file webpack.config.js.

1 answer

0


Because it is a project with Vue cli 2 > it is necessary to create the file Vue.config.js

module.exports = {
  configureWebpack: {
    module: {
      rules: [
        {
          test: /\.(pdf)(\?.*)?$/,
          use: [
            {
              loader: 'url-loader',
              options: {
                name: 'files/[name].[hash:8].[ext]'
              }
            }
          ]
        }
      ]
    }
  }
}

With this the webpack will understand and parse this type of file and allow handling through the generated Asset.

  • Thank you, you saved my life here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.