javascript - 反应:从调用状态的“blob”打开 PDF。使用“jsPDF”。返回:加载PDF文档失败
问题描述
我试图onClick
在调用axios.get()
. 从mysql数据库中获取数据。
打开pdf的按钮代码是
class DownloadPdf extends Component {
constructor(props) {
super(props)
this.pdfGenerator = this.pdfGenerator.bind(this)
}
pdfGenerator(blob){
console.log(blob)
var doc = new jsPDF('p', 'pt');
var blobPDF = new Blob([doc.output[blob.data]], { type: 'application/pdf'})
var BlobURL = URL.createObjectURL(blobPDF)
window.open(BlobURL)
}
render() {
return (
<td>
<button onClick={()=>{this.pdfGenerator(this.props.blob)}}>
Download PDF
</button>
</td>
)
}
输入道具是properties[obj].pdf_blob
blob 对象是:
{type: "Buffer", data: Array(94869)}
在父母中我使用过
.then(res => { this.setState({
properties: res.data.data,
isLoaded: true,
})
})
在我的 axios 请求从数据库中获取数据之后。
解决方案
推荐阅读
- xamarin - 如何在后面的代码中为框架设置高度请求?
- c# - 对于某些用户,长时间 ASP.Net 操作超时
- javascript - 错误:0:147:'xFromT':找不到匹配的重载函数
- java - 如果我只在 Spring Boot 中返回 Java 实例数组,则 http 响应正文中有一个空数组
- java - 如何防止 double 舍入到小数点后两位
- android - 带网络连接的 Android 后台服务
- javascript - Promise 仍然在 FireFox 中被阻止,但不是 Chrome?
- npm - Fork 并安装 Create React App 而不在 NPM 上发布
- fiware-orion - 如何在 Orion Context Broker 注册到 Context Provider 时包含 fiware-service 和 fiware-servicePath 标头?
- arrays - 如何在 Google 表格中对行进行排序