我在Vue项目中使用pdf.js希望实现在线预览pdf文件,利用pdf.js中的viewer.html打开pdf文件时,先是出现网上常有的
file origin does not match viewer’s
错误,在注释掉源文件中的代码后
// if (origin !== viewerOrigin && protocol !== 'blob:') {
// throw new Error('file origin does not match viewer\'s');
// }
又出现了
Uncaught (in promise) Error: 载入 PDF 时发生错误。
Failed to fetch错误,并且加载pdf地址时出现了跨域错误
请问这是服务器处理pdf文件出现的问题吗?应该怎么解决?
服务端添加CORS相关跨域头,这种建议在
nginx
层,不要下沉到业务