【发布时间】:2020-12-12 04:14:38
【问题描述】:
我一直关注this 在我的网站上查看我的 pdf,但由于某种原因它无法加载,我不确定我做错了什么。
这是我的代码,
import React, { Component } from 'react';
import {Document, Page} from 'react-pdf';
class Resume extends Component {
constructor(props){
super(props);
this.state = {
numPages: null,
pageNumber: 1
}
}
onDocumentLoad = ( {numPages}) => {
this.setState({numPages});
}
render() {
const {pageNumber, numPages} = this.state;
return (
<div>
<Document
file = '../files/resume.pdf'
onLoadSuccess = {this.onDocumentLoad}
>
<Page pageNumber = {pageNumber} />
</Document>
<p> Page {pageNumber} of {numPages}</p>
</div>
);
}
}
export default Resume;
这是我的目录和文件!
【问题讨论】:
-
我不确定,但我认为它不需要文件路径,而是需要发送请求的 URL。尝试将
resume.pdf放在public目录中,改写file='/resume.pdf'。 -
试过了,结果一样:(
-
将文件添加到
public目录后尝试重新启动服务器。 -
还是什么都没有。我确实收到了编译警告,比如:
-
require 函数的使用方式是无法静态提取依赖项...(对于 ...build/pdf.jf)