0
点赞
收藏
分享

微信扫一扫

vue-pdf 装饰器 访问pdf文档 带上cookie

古得曼_63b6 2022-03-30 阅读 69
python

【问题】

后台做了访问PDF文档需验证前端带过来的token,前端vue-admin-template查看pdf文档,使用的是import pdf from 'vue-pdf',axios在main.js中设置withCredentials后可以带上cookie,然后pdf用到的promise异步怎么携带cookie始终不清楚,查看官方文档【参考网址】中有

Public static methods
createLoadingTask(src[, options])
src: see :src prop
options: an object of options. This function creates a PDFJS loading task that can be used and reused as :src property.
The loading task is a promise that resolves with the PDFJS pdf document that exposes the numPages property (see example below).
beware: when the component is destroyed, the object returned by createLoadingTask() become invalid.

Supported options:

onPassword: Callback that's called when a password protected PDF is being opened.
onProgress: Callback return loading progress.
withCredentials: Wheter or not to send cookies in the fetch request.

中也有withCredentials,设置后应该就可以带上cookie,故修改代码如下

#原代码
this.pdfsrc = pdf.createLoadingTask(this.src)

#修改后如下
this.pdfsrc = pdf.createLoadingTask(this.src, {withCredentials:true})

【解决办法】

【参考网址】

GitHub - FranckFreiburger/vue-pdf: vue.js pdf viewer

举报

相关推荐

0 条评论