📌  相关文章
📜  在反应应用程序中添加 pdf - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:52.641000             🧑  作者: Mango

代码示例1
import React, { PureComponent } from "react"
import { Document, Page } from "react-pdf/build/entry.webpack"
import throttle from "lodash.throttle"
import pdf from "./pdf.pdf"

class App extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {width: null}
    this.throttledSetDivSize = throttle(this.setDivSize, 500)
  }

  componentDidMount () {
    this.setDivSize()
    window.addEventListener("resize", this.throttledSetDivSize)
  }

  componentWillUnmount () {
    window.removeEventListener("resize", this.throttledSetDivSize)
  }

  setDivSize = () => {
    this.setState({width: this.pdfWrapper.getBoundingClientRect().width})
  }

  render() {
    return (
      
this.pdfWrapper = ref}>
) } } class PdfComponent extends PureComponent { render() { return (
) } } export default App