该插件将会把页面的内容完整的打印出来,保证打印样式跟页面样式统一。
1.安装插件
npm install --save react-to-print
2.引入插件
import ReactToPrint from 'react-to-print';
3.使用插件
//触发按钮
const componentRef = useRef()
<div>
<ReactToPrint
trigger={() => <a href="#">打印</a>}
content={() => componentRef.current}
/>
//打印内容
<div ref={componentRef }>
xxxxxxxx
<div/>
</div>