【发布时间】:2021-10-26 22:24:40
【问题描述】:
我正在尝试从我的后端获取 pdf 文件并将其显示在页面上。我正在使用 react-pdf 库 https://www.npmjs.com/package/react-pdf 。但是我遇到了一个错误
文件中的参数无效,需要 Uint8Array、字符串或 参数对象
你能帮帮我吗
import { Document, Page } from 'react-pdf';
<Document file={() => dispatch(downloadAgreement())}>
<Page pageNumber={pageNumber} />
</Document>
export const downloadAgreement = () => (dispatch) => {
return axios(`https://test-zdc/pdf`, {
method: 'GET',
responseType: 'blob'
}).then((res) => {
const file = new Blob([res.data], { type: 'application/pdf' });
const fileURL = URL.createObjectURL(file);
return fileURL;
});
};
【问题讨论】:
-
你能把它放在codesandbox上吗?