vue项目中下载静态资源里的pdf文件

1.把文件放在项目目录src/assets文件下

vue项目中下载静态资源里的pdf文件_第1张图片

2.在项目是用a标签下载

        
          

以上项目运行会报错

Failed to compile.
./src/assets/download.pdf 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders (Source code omitted for this binary file)

3.需要在vue.config.js中配置!!!

vue项目中下载静态资源里的pdf文件_第2张图片

具体配置代码:
 

 configureWebpack: {
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    module: {
      rules: [{
        test: /\.pdf$/,
        use: [{
          loader: 'url-loader',
          options: {
            name: 'files/[name].[ext]'
          }
        }]
      }]
    }
  },

你可能感兴趣的:(pdf)