1.把文件放在项目目录src/assets文件下
2.在项目是用a标签下载
<a
:href="require('@/assets/download.pdf')"
download="使用说明.pdf"
target="_blank"
>
<img src="@/assets/banner.png" class="bannerimg"
/></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中配置!!!
文章来源:https://www.toymoban.com/news/detail-828929.html
具体配置代码:
文章来源地址https://www.toymoban.com/news/detail-828929.html
configureWebpack: {
name: name,
resolve: {
alias: {
'@': resolve('src')
}
},
module: {
rules: [{
test: /\.pdf$/,
use: [{
loader: 'url-loader',
options: {
name: 'files/[name].[ext]'
}
}]
}]
}
},
到了这里,关于vue项目中下载静态资源里的pdf文件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!