[英]How can i hold my datas in page when ı change active page in React.js?
[英]How can I add existing pdf file to my React.js page?
有人可以向我解釋我應該如何將現有的 pdf 文件添加到我的 React 網頁中嗎?
我開發了這個組件用於我的項目
import React, { Component } from "react";
import Axios from 'axios';
class DPFReportViewer extends Component {
_isMounted = false;
constructor(props) {
super(props);
this.state = {
PdfURL: ""
};
}
componentWillUnmount() {
this._isMounted = false;
}
componentDidMount() {
this._isMounted = true;
this.setState({ PdfURL: '' });
Axios.post(
'/Report/RunReport/',{ FileName: this.props.repFileName }, {
responseType: 'arraybuffer',
headers: {
'Accept': 'application/pdf'
}
).then((response) => {
if (this._isMounted && response.data) {
let blob = new Blob([response.data], { type: 'application/pdf' })
let fileURL = window.URL.createObjectURL(blob);
this.setState({ PdfURL: fileURL });
}
}).catch(error => {
console.log(error);
})
}
render() {
return (<div>
<embed src={this.state.PdfURL} width="100%" height="500px" type="application/pdf" style={{ overflow: "auto", width: "100%", height: "500px", border: "1px groove rgba(0, 0, 0, 0.5)" }} />
</div>
)
}
};
export default DPFReportViewer;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.