1.把文件放在项目目录src/assets文件下
2.在项目是用a标签下载
html
<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中配置!!!
具体配置代码:
javascript
configureWebpack: {
name: name,
resolve: {
alias: {
'@': resolve('src')
}
},
module: {
rules: [{
test: /\.pdf$/,
use: [{
loader: 'url-loader',
options: {
name: 'files/[name].[ext]'
}
}]
}]
}
},